Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ to VB

Status
Not open for further replies.

Brewman76

Programmer
Mar 27, 2001
50
US
I am working on some C++ code that I would like to convert to VB.

I have a message callback and the LPARAM being passed back is a struct (called X here). The C++ line of code is:

memcpy &x, (BYTE*)lParam, 64

Anyways.. I have struct X as a UDT, setup my subclassing, and added my RtlMoveMemory declare. Here is my line of code in my VB app:

dim x as x_udt

CopyMemory x, cbyte(lparam),64

My problem is that the UDT x does not have any data filled in. It looks like I just dim'ed it and that's it. I have also tried various combinations using VarPtr and Byval but I get the same result. I know I have to use CByte() otherwise it crashes. It's as if the UDT is being passed back by value instead of by reference.

I know (or I think anyways) that 64 is the correct length since that is what both Sizeof(x) in C++ and Len(x) in VB are returning.

Any ideas?
 
I don't understand the CByte thing for VB. For C++ I can understand, 'cause you need to cast it to a pointer to a variable of type "byte". But I would think that VB needs an uncasted long for any pointer.
It's a bit difficult for me to test without writing a lot of code, but doesn't this work:

Code:
CopyMemory x, ByVal lParam, LenB(x)

Remedy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top