Results 1 to 8 of 8

Thread: bad dll calling convention

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2001
    Posts
    54

    Question bad dll calling convention

    here is C function:

    int Dosth (char inflag)

    here is calling from VB:

    public declare function Dosth lib "**.dll" (byval flag as byte) as long

    dim a as byte
    dim ret as long
    ret=Dosth(a)

    when I call Dosth, got "bad dll calling convention"..... is it because the dll itself(it is now a try version dll) or my vb code?

    Thanks if you can answer.

    Last edited by ejudy; Jan 18th, 2002 at 12:02 AM.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    int WINAPI Dosth (char inflag)
    Try that. You'll need to #include <windows.h> for that to work though (what compiler are you on? If it's MSVC, use __stdcall and don't bother including the header).

    Then, you need a .def file to define the names for the functions.

    I posted a tutorial on the forum somewhere, search for "export" under my name.
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2001
    Posts
    54
    Thanks, parksie.

    Now I can call function in the dll. Here is another question : how can i trace and debug the function in dll when I call them using vb? I just want to know if the correct value is paased to the C function.....any suggestion?


    Tnx lot.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That depends very significantly on your debugger...I'm not sure whether there's any easy way to debug a VB program into the DLL...you might be able to do it with some serious messing with the VC++ debugger but I wouldn't be able to describe it
    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

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2001
    Posts
    54

    THANKS AGAIN :)

    I know, it is not so easy. Right now, I just add code to write some data to file to check the procudure. (maybe not a good way, but I can get some feedback).

    Now I met another interesting question. I was struggling all day but coundn't figure out. Maybe some of you had experience before. I would greatly appreciate if you'd like to have a look and give your conments.

    Here is code in C++(Dll):
    Code:
    typedef struct _user {
        ULONG      ID;
        char  name[64];
    } User;
    typedef struct _userList {
        ULONG  count;
        User      users[1];
    } UserList
    
    
     DWORD  m_numUsers;
     User       m_users[100];
    
    int GetUsers( UserList *outList )
    {
        User  *ptr = &outList->users[0];
        outList->count = m_numUsers;
        for( int i = 0; i < (int)m_numUsers; i++ ) {
            memcpy( ptr, &m_users[i], sizeof(User) );
            ptr++;
        }
        return 0;
    }
    Here is VB code
    Code:
    Public Type User
        ID         As    long
        Name    As   String * 64              
    End Type
    Public Type UserList
        Count     As  Long       
        Users()   As  User
    End Type
    Public Declare Function GetUsers Lib "user.dll" _
        (ByRef uList As UserList) As long
    
    private sub cmd_click()
         Dim uList As UserList
         lRet = GetUsers(uList)//memory can't be read..... 
         lCount = uList.Count
    End sub
    P.S.
    oh, I didn't expected to get a such a quick answer. I just made misoperation when I trying to edit my code.(sorry about that).
    Last edited by ejudy; Jan 18th, 2002 at 06:30 PM.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Please, please, please use [ code ] [ /code ] tags! It makes it almost unreadable with all the spacing gone, since that's the best way of finding the scope of things.

    It's very difficult to understand a long piece of code in a browser window with all the spacing gone!

    The problems you're running into here are more likely to be structure padding related, which I can't help with since I haven't used VB for a VERY long time, and can't remember exactly how it does it. Either way, you can't make any assumptions about how they're stored internally.
    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

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I somehow managed to jump into the VC++ debugger from VB, but I can't really remember how. But
    _asm int 3
    will work in VC++ to kick you into the debugger. You need to compile in debug mode to do this. The problem is that once you stop the debugger, VB will close (if you ran your app from within), so make sure you saved everything and have a link to start it again at hand. It can get VERY annoying.
    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.

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2001
    Posts
    54
    Thank you for your help!

    Cornedbee, I 'll have a try.


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