Original Post
Hi guys... I've got a dll, called Encryption.dll. I got Exception when I use it in my PC, but when I transfer the program to other PC, it works fine ! Here's the detail : Encryption.tlh Encryption.tli And, here's my class : MyEnkrip.h MyEnkrip.cpp It always throws exception in hasil=x->Encrypt(&b); instruction (But I believe that I already get error in CreateInstance, since that CREATEINSTANCE Macro throws error). What should I do ? Any advice ? Thanks.
// Created by Microsoft (R) C/C++ Compiler Version 12.00.9782.0 (f4c6d585).
//
// d:\program samples\060429\btserver\debug\Encryption.tlh
//
// C++ source equivalent of Win32 type library Encryption.dll
// compiler-generated file created 05/01/06 at 11:03:18 - DO NOT EDIT!
#pragma once
#pragma pack(push, 8)
#include <comdef.h>
namespace Encryption2 {
//
// Forward references and typedefs
//
struct __declspec(uuid("732a10c5-7c91-421f-a626-4a6335d74e6b"))
/* dual interface */ _Encrypt;
struct /* coclass */ Encrypt;
//
// Smart pointer typedef declarations
//
_COM_SMARTPTR_TYPEDEF(_Encrypt, __uuidof(_Encrypt));
//
// Type library items
//
struct __declspec(uuid("732a10c5-7c91-421f-a626-4a6335d74e6b"))
_Encrypt : IDispatch
{
//
// Wrapper methods for error-handling
//
_variant_t Encrypt (
VARIANT * Source );
_variant_t Decrypt (
VARIANT * Source );
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall raw_Encrypt (
VARIANT * Source,
VARIANT * _arg2 ) = 0;
virtual HRESULT __stdcall raw_Decrypt (
VARIANT * Source,
VARIANT * _arg2 ) = 0;
};
struct __declspec(uuid("7e5acc22-3a01-4179-aba0-abf13a689aad"))
Encrypt;
// [ default ] interface _Encrypt
//
// Wrapper method implementations
//
#include "d:\program samples\060429\btserver\debug\Encryption.tli"
} // namespace Encryption2
#pragma pack(pop)
// Created by Microsoft (R) C/C++ Compiler Version 12.00.9782.0 (f4c6d585).
//
// d:\program samples\060429\btserver\debug\Encryption.tli
//
// Wrapper implementations for Win32 type library Encryption.dll
// compiler-generated file created 05/01/06 at 11:03:18 - DO NOT EDIT!
#pragma once
//
// interface _Encrypt wrapper method implementations
//
inline _variant_t _Encrypt::Encrypt ( VARIANT * Source ) {
VARIANT _result;
VariantInit(&_result);
HRESULT _hr = raw_Encrypt(Source, &_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _variant_t(_result, false);
}
inline _variant_t _Encrypt::Decrypt ( VARIANT * Source ) {
VARIANT _result;
VariantInit(&_result);
HRESULT _hr = raw_Decrypt(Source, &_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _variant_t(_result, false);
}
#define INITGUID
#import "Encryption.dll" rename_namespace("Encryption2")
using namespace Encryption2;
class MyEnkrip
{
public:
//CString enkripsi(CString pt);
MyEnkrip();
~MyEnkrip();
char* enkripsi(char *pt);
char* dekripsi(char *pt);
};
#include "MyEnkrip.h"
#define COPYSTRING(s1, s2, len) {for(int i=0; i<len; i++){if(s2==0) {s1=0;break;}else s1=s2;}s1[len-1]=0;}
#define CREATEINSTANCE(sp,riid) { HRESULT _hr =sp.CreateInstance( __uuidof( riid ) ); if (FAILED(_hr)) _com_issue_error(_hr ); }
MyEnkrip::MyEnkrip()
{
::CoInitialize(NULL);
}
MyEnkrip::~MyEnkrip()
{
::CoUninitialize();
}
char* MyEnkrip::enkripsi(char *pt)
{
_EncryptPtr x;
//CREATEINSTANCE(x, Encrypt);
x.CreateInstance(__uuidof(Encrypt));
char pas_baru[16];
_variant_t inpu(pt);
inpu.ChangeType(VT_BSTR);
VARIANT b(inpu);
_variant_t hasil;
hasil=x->Encrypt(&b); //////THIS ONE IS THE PROBLEM
hasil.ChangeType(VT_BSTR);
COPYSTRING(pt, hasil.bstrVal, strlen(pt));
x.Release();
//return ct;
return pt;
}
char* MyEnkrip::dekripsi(char *pt)
{
_EncryptPtr x;
x.CreateInstance(__uuidof(Encrypt));
char pas_baru[16];
//CString ct;
_variant_t inpu(pt);
inpu.ChangeType(VT_BSTR);
VARIANT b(inpu);
_variant_t hasil;
hasil=x->Decrypt(&b);
hasil.ChangeType(VT_BSTR);
COPYSTRING(pt, hasil.bstrVal, strlen(pt));
//ct=hasil.bstrVal;
//strcpy(pt, ct);
x.Release();
//return ct;
return pt;
}