String-Problems calling callback function in VB6 ActiveX-Control from C++ 
Author Message
 String-Problems calling callback function in VB6 ActiveX-Control from C++

Hi!

I'm relative new to Visual Basic, but pretty comfortable with C/C++.
I want to call a C/C++ generated DLL from within a VB ActiveX Control.
More precisely, I want to give the DLL the pointer of a callback-
function
and the DLL calls this function in the ActiveX Control.

While I managed it to set up the callback-mechanism, I have problems
with
the data. The C/C++ DLL calls the VB ActiveX function with a C/C++
struct
like this:

typedef struct tagDATA {
    long Number1;
    long Number2;
    char String1[100];
    char String2[100];

Quote:
} *LPDATA;

The prototype in C/C++ looks like this:

void ActiveXCallbackFunction(LPDATA lpData);

I converted this to VB:

Public Type DATA
    Number1                       As Long
    Number2                       As Long
    String1                       As String * 100
    String2                       As String * 100
End Type

The Callback-Function in the VB Control looks like this:

Public Sub CallbackFunction(ByRef lpData As DATA)
    MsgBox CStr(lpData.Number1) ' Output: ok
    MsgBox CStr(lpData.Number2) ' Output: ok
    MsgBox lpData.String1       ' Output: "???"
    MsgBox lpData.String2       ' Output: "???"
End Sub

The problem is, that the numbers are transmitted correctly,
but the strings are a mess, displaying "?" and spaces.

I have'nt found a way to do it in the documentation,
so I hope someone of you VB-pro's can help me on this.

TIA
Jochen

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 28 Oct 2002 03:00:00 GMT  
 String-Problems calling callback function in VB6 ActiveX-Control from C++
Jochen,

This is most likely a ANSI/Unicode issue. The C++ code sends ANSI
characters to your VB function, which expects Unicode characters in
the structure. Try it like this instead:

Public Type DATA
    Number1                       As Long
    Number2                       As Long
    String1(0 To 99)              As Byte
    String2(0 To 99)              As Byte
End Type

Public Sub CallbackFunction(ByRef lpData As DATA)
    MsgBox CStr(lpData.Number1)
    MsgBox CStr(lpData.Number2)
    MsgBox StrConv(lpData.String1, vbUnicode)
    MsgBox StrConv(lpData.String2, vbUnicode)
End Sub

Mattias

____________________________________________

    http://hem.spray.se/mattias.sjogren/
              Docendo discimus



Mon, 28 Oct 2002 03:00:00 GMT  
 String-Problems calling callback function in VB6 ActiveX-Control from C++


Quote:
> Jochen,

> This is most likely a ANSI/Unicode issue. The C++ code sends ANSI
> characters to your VB function, which expects Unicode characters in
> the structure. Try it like this instead:

> Public Type DATA
>     Number1                       As Long
>     Number2                       As Long
>     String1(0 To 99)              As Byte
>     String2(0 To 99)              As Byte
> End Type

> Public Sub CallbackFunction(ByRef lpData As DATA)
>     MsgBox CStr(lpData.Number1)
>     MsgBox CStr(lpData.Number2)
>     MsgBox StrConv(lpData.String1, vbUnicode)
>     MsgBox StrConv(lpData.String2, vbUnicode)
> End Sub

Yes, it seems this was a unicode-problem. I changed my code according to
your example and everything works fine now. Thank you,

Jochen

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 29 Oct 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. creating a callback function in c++ dll to callback a VB function in an exe

2. HOWTO Call a VB Callback function from VB ActiveX control

3. HOWTO Call VB Callback function from ActiveX control

4. HOWTO Call VB Callback function from ActiveX control

5. problems with C/C++ DLL passing arguments to VB Callback Function

6. Problem with calling VB ActiveX from callback

7. Intermitent problem calling function in ActiveX Control

8. Calling a C++ DLL function which takes an C++ object as parameter

9. Problems calling a C++ ACTIVEX DLL?

10. Calling VB ActiveX DLL from Visual C++ problem

11. calling VB ActiveX method from C++ problem

12. calling a C++ compiled program from within MSIE using ActiveX control

 

 
Powered by phpBB® Forum Software