Hey Guru
I have a small problem that might have a simple solution but I miss some
basic concept...
I have a class written in C++
I have a vb interface that what to use tha class.
I good with VB but dumb in C++.
The code in C++ communicate with com ports and do EXACTLY what I want. In
VB, I get unexpected result with the MsComm.ocx ActiveX Control (see
http://www.*-*-*.com/
ic/VB_Controls/Q_20540086.html).
I tried to use VP API but it VB IDE keeps crashing with Access Violation...
SO i need to acces my C++ class from VB.
Two way to do it
1- Atl Server Component : Create the equivalent of an ActiveX DLL with the
COM support... OUCH, to heavy for me
2- Keeping alive information between 2 call to a DLL Written in C++
I try to do the following:
---- C++ -----
//==================================================================
unsigned long _stdcall InitObject(void)
//==================================================================
// CDspOperation construction
// 1- Awake the manager that governs various communication states
// 2- Return the pointer???
//==================================================================
{
Tserial_event *objSerial; // Pointer to the communication library
objSerial = (Tserial_event*) malloc(sizeof(objSerial));
objSerial->SetComPort(3);
return (unsigned long) &objSerial;
Quote:
}
//==================================================================
int _stdcall TestObjectInit(unsigned long intObjAddress)
//==================================================================
// CDspOperation construction
// 1- Reconnect to object memory space
// 2- Return the value set before ???
//==================================================================
{
Tserial_event *objSerial; // Pointer to the communication library
int intRetVal = 0;
objSerial = (Tserial_event*) intObjAddress;
return objSerial->GetComPort();
Quote:
}
---- VB -----
Private Declare Function InitObject Lib "...\DspAccessV1.dll" () As Long
Private Declare Function TestObjectInit Lib "...\DspAccessV1.dll" (ByRef
plngPointer As Long) As Long
Private Declare Function ReleaseObject Lib "...\DspAccessV1.dll" (ByRef
plngPointer As Long) As Long
Private Sub Form_Load()
Dim lngRep As Long
lngRep = InitObject() ' Mem Allocation and receive the address
of the obj
MsgBox TestObjectInit(lngRep) ' Get info previously set (should be 3)
Call ReleaseObject(lngRep) ' Flush the memory at the address of the
obj
End Sub
--------------------------
What is wrong with that, is it possible, the reason for this is that I need
to call TestObjectInit more than 100 time sin a loop.
Also : The One of the function must return a string of data : byval on vb
side... how to do it in the C++ side...
Any help would be appreciated...
TIA
Manuel