Results 1 to 7 of 7

Thread: dll call working from compiled exe and not from within VB6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    97

    Question 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

  2. #2
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    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.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    97

    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

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    97

    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
  •  



Click Here to Expand Forum to Full Width