Problem Connecting VB front end to C++ back end 
Author Message
 Problem Connecting VB front end to C++ back end

I am trying to pass a VB user-defined to a C language function in a
dll that will send this VB user-defined type (which corresponds to a
C structure) via a socket to the C++ server.  I can call a void function
in the dll and get a return value just fine.  the minute I try to use a
user defined type as a parameter,  I get run-time errors.

I could use strings with some char as a delimiter but I want to use
well defined message structures like you would in any C/C++
application.

In my Module.bas file:
-----------------------------

Public Const MAX_USER_NAME_LEN = 25 + 1

Public Type StdMessageHeader
    TotalMessageLength As Long
    MessageType As Long
    MessageSubType As Long
    MessageVersion As Long
    TransactionId As Long
    SenderPid As Long
    SenderAppId As Long
    DestAppId As Long
    SendingUserName As String * MAX_USER_NAME_LEN
    SendingHostName As String * MAX_USER_NAME_LEN
End Type

Public MYLogin As StdMessageHeader

Public Declare Function SendData Lib "CygnSock" (ByRef StdMessageHeader) As
Integer

In my pushbutton to send data:
-----------------------------------------

Private Sub LoginBut_Click()

Dim Status As Integer

MYLogin.TotalMessageLength = 84
MYLogin.MessageType = 1
MYLogin.MessageSubType = 1
MYLogin.SendingUserName = "JEFF" + Chr(0)
MYLogin.SendingHostName = "PROZAC" + Chr(0)

Status = SendData(MYLogin)

End Sub

I get a run time err:
-------------------------

Only user-defined types defined in public object modules can be coerced to
or from a variant or passed to late bound functions.

I don't understand what the compiler is asking me to do,  any ideas?

    Thanks,

    Jeff



Mon, 03 Sep 2001 03:00:00 GMT  
 Problem Connecting VB front end to C++ back end
I think (and i do emphasise the word 'think') you have to pass a pointer to
the begining of the structure by using the function VarPtr. This is an
unsupported function so dont bother looking in the help files.

Status = SendData(VarPtr(MYLogin))

I'd be interested to know if this works for you



Tue, 04 Sep 2001 03:00:00 GMT  
 Problem Connecting VB front end to C++ back end
Your Declare is not quite correct.

Quote:
>Public Declare Function SendData Lib "CygnSock" _
>(ByRef StdMessageHeader) As Integer

Should be something like:

Public Declare Function SendData Lib "CygnSock" _
(ByRef LoginVar As StdMessageHeader) As Long

--
     Jim Mack
     MicroDexterity, Inc

     http://www.microdexterity.com



Quote:

>I am trying to pass a VB user-defined to a C language function in a
>dll that will send this VB user-defined type (which corresponds to a
>C structure) via a socket to the C++ server.  I can call a void
function
>in the dll and get a return value just fine.  the minute I try to use a
>user defined type as a parameter,  I get run-time errors.

>I could use strings with some char as a delimiter but I want to use
>well defined message structures like you would in any C/C++
>application.

>In my Module.bas file:
>-----------------------------

>Public Const MAX_USER_NAME_LEN = 25 + 1

>Public Type StdMessageHeader
>    TotalMessageLength As Long
>    MessageType As Long
>    MessageSubType As Long
>    MessageVersion As Long
>    TransactionId As Long
>    SenderPid As Long
>    SenderAppId As Long
>    DestAppId As Long
>    SendingUserName As String * MAX_USER_NAME_LEN
>    SendingHostName As String * MAX_USER_NAME_LEN
>End Type

>Public MYLogin As StdMessageHeader

>Public Declare Function SendData Lib "CygnSock" (ByRef

StdMessageHeader) As

- Show quoted text -

Quote:
>Integer



Wed, 05 Sep 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Trying to Create a communicator for VB.net Front End and SQL 2000 back end

2. VB Front end dll loses connection to back end SQL server db after an hour

3. Packaging a VB front end/Access back end application

4. Access Back End, VB Front End -- Why?

5. Access Back End, VB Front End -- Why?

6. A2k: Controlling a back-end MDB from its FRONT-end MDB

7. A2K Updating Back End with new fields from Front End

8. Compact the back-end data from the front-end

9. Corrupted back end corrputs all front ends!

10. Splitting db in front end and back end

11. Compact back-end front-end

12. Front-End & Back-End

 

 
Powered by phpBB® Forum Software