Results 1 to 7 of 7

Thread: UDT passed to a DLL

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    london
    Posts
    41

    UDT passed to a DLL

    Hi folks, I must be stupid or something. I can't get the following
    very simple code to work. Any help would be greatly appreciated as I can't find the answer. Regards, Mark ([email protected])
    P.S The stuff below this line pastes straight into a .BAS file.
    ==============================================

    'I expect the following output from Sub CreateRecords...
    ' 1
    ' 2
    'A Variable Length String
    ' 3
    ' 4
    ' 5
    'Another Variable Length String
    ' 6

    Type RECORD
    A As Double
    B As Long
    C As String
    D As Long
    End Type

    Global Recs(1 To 2) As RECORD

    Declare Sub DLLDillon Lib "\Chappel.23\Source\C\Useful23\Debug\useful23.dll" (TwoRecords As RECORD)

    Sub CreateRecords()
    Recs(1).C = "A Variable Length String"
    Recs(2).C = "Another Variable Length String"
    Call DLLDillon(Recs(1))

    Debug.Print Recs(1).A
    Debug.Print Recs(1).B
    Debug.Print Recs(1).C
    Debug.Print Recs(1).D
    Debug.Print Recs(2).A
    Debug.Print Recs(2).B
    Debug.Print Recs(2).C
    Debug.Print Recs(2).D
    End Sub


    'My attempt at the 'C' end follows...

    'struct RECORD
    '{
    ' double a;
    ' long b;
    ' long c;
    ' long d;
    '};

    'VOID FAR PASCAL DLLDillon(struct RECORD FAR* Recs)
    '{
    ' Recs[0].a = 1;
    ' Recs[0].b = 2;
    ' //Recs[0].c = Don't even touch field 'c'
    ' Recs[0].d = 3;
    ' Recs[1].a = 4;
    ' Recs[1].b = 5;
    ' //Recs[0].c = Don't even touch field 'c'
    ' Recs[1].d = 6;
    '}
    Regards, Mark

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What's the problem?
    Try to use (ByVal pRecords as Long) as parameters in the declare statement. Then pass VarPtr(Recs(1)) as argument. On the C side nothing changes.
    C side: FAR and PASCAL are not used anymore. In VC++, PASCAL is replaced by __stdcall, other compilers will have similar things. FAR is not needed in 32-bit environments.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    __stdcall == WINAPI, and is the more general across compilers.

    What I don't get is MS's love of having lots of names for EXACTLY THE SAME SODDING TYPE!

    *rant over*
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by parksie
    __stdcall == WINAPI, and is the more general across compilers.

    What I don't get is MS's love of having lots of names for EXACTLY THE SAME SODDING TYPE!

    *rant over*
    Layering parksie layering what if microsoft wanted to change a datatype? Then they'd have to take the complaints of all programmers that would need to change it in every single little app.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Still doesn't explain why there's STDCALL, WINAPI, CALLBACK, PASCAL, and most likely others as well for what is essentially __stdcall.

    (However, they still do stupid things like typedef float FLOAT )
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    same datatype for different purposes, you'll learn to know what it means in BORK
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    WINAPI and CALLBACK were different things in Win16...

    And imagine a win32 compiler that doesn't know __stdcall (a gcc port maybe). This could be helped by simply adding one line in the sdk headers
    #ifdef THIS_IS_MY_OWN_COMPILER
    #define WINAPI _my_weird_stdcall_name
    #endif

    And everything will be compiled as it should...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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