CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: VB and DLLs

  1. #1
    Join Date
    Dec 1999
    Posts
    8

    VB and DLLs

    Periodically I have VB crash when I call a C++ DLL in a VB program. This only occurs in the VB IDE and not when the program is made into a .exe. Is this just a bug in VB?






  2. #2
    Guest

    Re: VB and DLLs

    You get problems like this using the cool API functions that use callbacks.
    Basically, a callback is a path for a windows procedure (such as Form_Click equivalent for the desktop etc.) so that a certain sub in your code gets called also. If you say what function it is, maybe i could help, but otherwise there are load of things that it could be.
    One ofv the main things could be that WindowsAPI always insists on having the same thing passed to it that is specifies (as in an integer to a long is not allowed or a ByRef to a ByVal is not either).
    Sometimes VB does not like some things (like multithreading - yes it is *just* possible). So it will crash the IDE but will work fine outside of it.
    Hope its helped you!

    Kris with a K


  3. #3
    Join Date
    Apr 2000
    Location
    Winston-Salem, NC
    Posts
    32

    Re: VB and DLLs

    You must be careful when calling C++ from VB in the IDE. Access violations are easy to trigger because of several reasons.

    One is callbacks. Some C++ functions (like SetTimer) require you to pass the memory location (with AddressOf) to the function so that the routine may call your code directly. If you End or press the Stop button your temporary runtime memory is cleared abruptly and the C++ function calls back to a function that no longer exists, thus causing a memory access violation and the death of your IDE. (Moral : save frequently)

    Another common cause of your problem is passing the wrong data type or incorrect buffer length to a C++ routine. C++ from VB is fragile in the IDE...

    Good luck

    == Ali R. Tahbaz, MCSD ==========================
    "Whether you think that you can, or that you can't, you are usually right."
    --Henry Ford

  4. #4
    Join Date
    Sep 1999
    Location
    Northern Utah, U.S. of America
    Posts
    38

    Re: VB and DLLs

    An addendum to "TAHBAZA"'s 2nd paragrah response...

    First Shorts in VC++ are an Integer in VB
    Ints in VC++ are a Long in VB.
    Secondly: YOU MUST pass the same string length between a DLL and VB and you MUST pass all strings by 'BYVAL', OR things may start to happen. I learned the very hard way. The DLL File that I made is a non-MFC one. And I used 'WINAPI' stuff.

    VBFingers.




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

Featured