|
-
Jan 17th, 2002, 11:59 PM
#1
Thread Starter
Member
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.
-
Jan 18th, 2002, 04:54 AM
#2
Monday Morning Lunatic
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
-
Jan 18th, 2002, 01:34 PM
#3
Thread Starter
Member
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.
-
Jan 18th, 2002, 02:39 PM
#4
Monday Morning Lunatic
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
-
Jan 18th, 2002, 06:00 PM
#5
Thread Starter
Member
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.
-
Jan 18th, 2002, 06:08 PM
#6
Monday Morning Lunatic
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
-
Jan 21st, 2002, 06:23 PM
#7
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.
-
Jan 21st, 2002, 08:18 PM
#8
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|