|
-
Nov 26th, 2008, 08:34 AM
#1
Thread Starter
Lively Member
dll call working from compiled exe and not from within VB6
Hi,
I'm having problems calling the following function in a dll written in C++, from VB6:
Code:
Private Declare Sub HaxAnim_setMarker Lib "HaxMio.dll" (ByVal haxAnim As Long, ByVal StartFrame As Integer, ByVal EndFrame As Integer, ByVal looping As Boolean)
I've converted it from the C++ call which is:
Code:
void __stdcall HaxAnim_setMarker(void * haxAnim, int startFrame, int endFrame, bool looping)
We are currently able to compile an .exe in VB and debug it in C++.
The problem is with startFrame. When running from the .exe the dll receives a meaningful value (e.g. 3), but when running from within VB it receives a garbled value (e.g. 10384030283), i.e. not the one I send it from within VB code.
Can anyone think of a reason why this call would be sending a correct value as a compiled exe and a bad value from within vb6.
thanks
Paul
-
Nov 26th, 2008, 10:33 AM
#2
Hyperactive Member
Re: dll call working from compiled exe and not from within VB6
Not sure why but if it works when compiled that's what matters right? Sure it may be harder to debug because of the extra step but it's not a huge deal IMO.
-
Nov 26th, 2008, 10:54 AM
#3
Re: dll call working from compiled exe and not from within VB6
I don't think the declaration or the C++ code is the problem.... what is StartFrame? How are you calling this function?
-tg
-
Nov 26th, 2008, 11:20 AM
#4
Thread Starter
Lively Member
Re: dll call working from compiled exe and not from within VB6
Hi,
I will be running this app from VB, I won't ever need it as an .exe. It's far more valuable for me to be able to debug on the fly, than to create an .exe. The software is control software, that only I am going to use.
StartFrame is an Integer value that I'm passing to SetMarker (which is the declared function from the .dll). If I add the code:
Code:
HaxAnim_setMarker AnimPointer, 3, 10, True
When I run the exe of the app, the .dll receives 3 for StartFrame (as has been coded) in the setMarker function. However if I run it from VB, it recieves a garbled value (like 129238232). All the other variables are received fine (either running the .exe or from VB).
It's a pretty obscure problem. I'm just curious if anyone has ever had a similar problem (and how they got around it).
Paul
-
Nov 26th, 2008, 11:38 AM
#5
Re: dll call working from compiled exe and not from within VB6
ummm..... you do realize that an int in C is an in32, while an integer in VB6 is only an int16.... which is the same as a short. So if you need an int in C, you need to declare it as a Long in VB6....
don't know if that's the problem, but I've never seen this problem before either.
-tg
-
Nov 26th, 2008, 06:44 PM
#6
Re: dll call working from compiled exe and not from within VB6
I have seen problems where a literal value (such as 3, 10, etc.) passed to an API "ByVal" will fail erratically. I wish I could pin down when and why it happens, but I have gotten around it by declaring a local variable and setting it to the literal, then passing this in the call.
Now I wonder if adding parentheses might solve the problem as well? I.e. (3) instead of 3 or 3&.
Should be easy enough to try anyway hmm? What do you have to lose?
I'd fix the Declare as suggested first though.
-
Nov 29th, 2008, 05:27 AM
#7
Thread Starter
Lively Member
Re: dll call working from compiled exe and not from within VB6
Yeah. It was the fact I was using Integer in VB for a Int C++ variable.
So, with a bit of trial and error I think I've worked out how the variables map:
C -> VB
Int -> Long
Float -> Single
BOOL -> Integer
STR -> String
Is this right?
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
|