C++ DLL Object and vb 
Author Message
 C++ DLL Object and vb

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



Wed, 24 Aug 2005 13:06:47 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. accessing objects in a c++ DLL from a c++ activeX control placed in a VB application

2. accessing objects in a c++ DLL from a c++ activeX control placed in a VB application

3. Passing VB DAO objects to C++ DLL functions?

4. HOWTO? Calling VB DLL from C++ DLL

5. I need testers for serial port comm DLL and alpha paging DLL (Delphi, C/C++, VB)

6. call a VB COM dll thru a C++ COM dll from a C program

7. call a VB COM dll thru a C++ COM dll from a C program

8. Show modeless form in VB ActiveX DLL from C++ MFC DLL

9. Creating custom object in C++ for VB

10. How to pass an ADODB.Stream object from VB to a method in a C++ component

11. Using C++ pooled object from VB

12. HELP: Debugging a COM automation DLL object in VB

 

 
Powered by phpBB® Forum Software