
Help - Calling ActiveX DLL function from VB and C++ returns different values
I call functions in an ActiveX DLL from both VB and C++ but I'm getting
different results from each. I think I'm doing the same thing in VB and C++.
If anyone can shed any light on this I'd be most grateful. The VB and C++
code are below:
VB:
Project has a reference to duspd.dll
Dim dxz As New DUS
Dim bvc As New BPD
Dim enc As String
dxz.Key = "LIC"
enc = bvc.Encode(dxz.Encrypt("ABCDE1"))
'The value of enc above is, say, "QWE"
In C++, I do the following:
#import "duspd.dll" rename("NO_ERROR", "BPD_NO_ERROR")
extern "C" __declspec(dllexport) int ValR(char *,char *);
int
ValR(char *a, char *b)
{
HRESULT hr;
DUSPDLib::_DUSPtr dxz;
DUSPDLib::_BPDPtr bvc;
BSTR key, ld, b3;
_bstr_t b1, b2;
hr = CoInitialize(NULL);
hr = dxz.CreateInstance (__uuidof (DUSPDLib::DUS));
hr = bvc.CreateInstance (__uuidof (DUSPDLib::BPD));
// no errors from above
key = SysAllocString (L"LIC");
d56->PutKey(&key);
ld = SysAllocString (L"ABCDE1");
b1 = dxz->Encrypt(&ld);
b3 = SysAllocString(static_cast<const wchar_t*>(b1));
b2 = bvc->Encode(&b3);
fprintf (f, "b2=%s\n", (char *)b2);
// **** The value I get when I print b2 to file is not "QWE" as I
expected, but some other string
SysFreeString......
bvc.Release();
dxz.Release();
CoUninitialize();
Quote:
}