Results 1 to 7 of 7

Thread: Passing a structure by reference to C++ DLL

  1. #1

    Thread Starter
    Hyperactive Member Gtarawneh's Avatar
    Join Date
    Mar 2002
    Location
    Unknown
    Posts
    382

    Question Passing a structure by reference to C++ DLL

    Hi,

    Confused where to post this since it has to do with both C++ and VB.

    Using C++, I've made a DLL library (ATL Component) which contains a strucutre. I want to expose the structure definition to the VB application as a data type so it can create a variable with this data type, manipulate it, and pass it by reference to functions in the DLL. Question is: How is that possible?

    Thanks in advance!

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    couldn't you just create a UDT in VB that has the same set of variables as your C structure?? like when you are using windows API and pass a rect UDT to an API function because it needs the rect structure for its return values.

    So if your structure is made up of 3 longs and a string, making a UDT of the same parameters should work for passing..

    this is just a guess.. I am not a C programmer so I am not sure if it will work

  3. #3

    Thread Starter
    Hyperactive Member Gtarawneh's Avatar
    Join Date
    Mar 2002
    Location
    Unknown
    Posts
    382
    Yeah, it's fine in theory, yet I lack the technique

    Am facing some trouble because whenever I try to make one of the variables passed into the function a UDT, I get some errors with the compile!

    Wonder if anyone could help, or post some code?!?!?

  4. #4
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    do you get error in vb or c?
    show the struct plz, so we can help you translate it to a udt.
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  5. #5

    Thread Starter
    Hyperactive Member Gtarawneh's Avatar
    Join Date
    Mar 2002
    Location
    Unknown
    Posts
    382
    Am getting the error in C++, anyway: the problem is technical as I said before, and I should face no problem translating the structure, here it is anyway:

    Code:
    typedef struct
    {
       int Piece[65];
       int AttackPiece[65];
       int BlackKingP;
       int WhiteKingP;
       int MSF1;
       int MSF2;
       int MyRate;
       int ByPassPos;
       int Cast1; //Black Long
       int Cast2; //Black Short
       int Cast3; //White Long
       int Cast4; //White Shor
    } ChessBoard;

  6. #6
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    The thing is that I don't know for sure how the C/C++ compiler you have will take the Int ?, as 16 bit or 32 bit, but it is more likely that it is 32 bit...

    So, the struct in VB should be like this:
    VB Code:
    1. Type ChessBoard
    2.    Piece(65 - 1) As Long
    3.    AttackPiece(65 - 1) As Long
    4.    BlackKingP As Long
    5.    WhiteKingP As Long
    6.    MSF1 As Long
    7.    MSF2 As Long
    8.    MyRate As Long
    9.    ByPassPos As Long
    10.    Cast1 As Long  ' Black Long
    11.    Cast2 As Long  ' Black Short
    12.    Cast3 As Long  ' White Long
    13.    Cast4 As Long  ' White Shor
    14. End Type

  7. #7

    Thread Starter
    Hyperactive Member Gtarawneh's Avatar
    Join Date
    Mar 2002
    Location
    Unknown
    Posts
    382
    Anyway, I've managed to do some roundabout solution. so I'll consider it resolved for me, Thanks All!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width