
how to use a VB active dll which include Form at a c++ program
Liuszhen,
Quote:
> You are right . I make a mistake .
> But there is an other question.
> Do you know how to get a string parameter
> from a vb activeX dll.I use this code in vc
> short bitInt,misInt;
> int st1;
> BSTR bstrDesc;
> BSTR aaa;
> char cFile[256];
> aaa=(char*)&cFile;
> sourceFile= (LPCTSTR)(&sFile);
> comparedFile= (LPCTSTR)(&cFile);
> try
> {
> CoInitialize(NULL);
> _ParameterInputPtr ptr;
> ptr.CreateInstance(_uuidof(ParameterInput));
> st1 = ptr->ParameterInput(aaa,&bitInt,&misInt);
> }
> catch(_com_error &e)
> {
> bstrDesc = e.Description();
> }
> CoUninitialize();
> the fuction in vb is write as
> Public Function ParameterInput(ByVal sourceFile As String, bitInt As
> Integer, misInt As Integer) As Long
> sourceFile = "aaaa"
> bitInt = 1
> misInt = 2
> ParameterInput = 3
> End Function
> but get a wrong address ,where did I make a mistake?
Several things
1- You can't create a BSTR by simply casting as you are doing now. BSTRs
have to be allocated and deallocated using SysAllocString() and
SysFreeString() and related functions.
2- If you want to change the value of sourceFile in your VB code, and
retrieve it from yout VC++ code, I think you should declare it ByRef, not
ByVal (but I'm not of VB guy, so I might be wrong).
3- The line aaa = (char*)&cFIle; is obviously incorrect, as you are taking
the address of the variable itself, not the address the array is stored at.
3- You are doing too many ugly casts in your C++ code, trying to get things
to compile. Most of them are incorrect, and other will simply break if you
try to compile your code for uincode.
--
Tomas Restrepo
http://members.xoom.com/trestrep/