Usinc VC++ written DLLs in VB
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Usinc VC++ written DLLs in VB

  1. #1
    Join Date
    Apr 1999
    Location
    Tampa, FL
    Posts
    114

    Usinc VC++ written DLLs in VB

    I'm biting the bullet to learn Visual Basic, because its just to productive to ignore. But a major priority with me will be finding a way to make use of the many stand alone DLLs I've written in VC++. Some of these contain C type functions, and others contain C++ classes, and I always import them at run time using the LoadLibrary() and associated API calls. If anyone can point me to some articles or books that specifically deal with this, I'd appreciate it! I'd hate to have to go back and re-work those DLLs if possible, but I'll do whatever I have to do. I'm sure I'm not alone in this, but I've found very little on the subject.

    Please forgive me if I cross-post this in the VC++ section.

    * * *
    * Second Star to the Right *

  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Usinc VC++ written DLLs in VB

    You can use LoadLibrary() in VB but it is not the easiest way of accessing a C/C++ dll from VB.

    A better way is to declare the import thus:

    Declare [ Sub | Function ] FunctionName Lib "dllname.dll" Alias "ExportedName" ([Argument As DataType]* ) [ As DataType ]

    For example, suppose you have a dll which is called "Finance.dll" and you have a function called "GetOverdraftLimit" which takes an account number (in the form of a string) and returns a double you could declare it thus:


    Declare Function GetOverDraftLimit Lib "Finance.dll" (byval lpAccountNumber as string) as Double




    The conversion between C/C++ data types (DWORD, UINT) to VB data types is best covered by the book [i]"The Visual basic programmers guide to the Win 32 API"[i] by Daniel Appleman (ISBN 1-56276-287-7)

    Hope this helps, as a start,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com/EventVB/Overview.htm - Flatten the API learning curve
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Apr 1999
    Location
    Tampa, FL
    Posts
    114

    Re: Usinc VC++ written DLLs in VB

    Just the fact that you say it's do-able gives me much hope. Especially as someone on the VC++ forum told me it is impossible to make VB understand C classes, functions, or calling conventions (such as __cdecl).

    The most important DLL I've written is a C (not C++) one that is, in effect, a data server. It uses static shared memory to implement interprocess communication between multiple programs that laod the same instance of the DLL, and provides notification of incomming messages either by polling, or by allowing the calling application to provide a callback function, while setting up a private thread to do the notification. It is an amazingly fast method of interprocess communication without any of the overhead of COM or file based data passing, as it works literally as fast as your processor can write to memory!

    The thing is, although this will likely be a "bear" to implement the first time in VB, andy means to get it done will be hugely worthwhile! Once done, I can have any number of C applications (or other DLLs) "attach" to this data server, and thus pave the way to using any and all the C/C++ written utilities I could ever come up with. I think the end result might be useful to many programmers that use boty VB and VC++, and will certainly make it available.

    I may have to stick with the "LoadLibrary" method for this one, if it is possible, no matter how much of a headache. The Data Server DLL has no export tables and I need the API calls to locate all its functions and create the function pointers templates so I can call them. A pain in C, and probably more of a pain in VB. But now that you know a little more about what I need to do, do you still feel it is possible, and that the "The Visual basic programmers guide to the Win 32 API" will tell me all the dirty details?

    Thanks so much for your time!

    * * *
    * Second Star to the Right *

  4. #4
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Usinc VC++ written DLLs in VB

    This sounds like what Sergei aka Ark is doing in http://www.freevbcode.com/ShowCode.Asp?ID=1863 this code example.

    Be warned, however, that it's pretty scarry stuff!

    HTH,
    D.

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com/EventVB/Overview.htm - Flatten the API learning curve
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  5. #5
    Join Date
    Oct 2003
    Location
    srilanka
    Posts
    88
    I hope this article may be useful to you sir.
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 2002
    Location
    tennessee
    Posts
    104

    re:

    Hi, I have written a post and added my dll creator program and done some explaining on a previous post by the name of:

    Calling a vc++ dll from vb.

    so just search for that and you'll get the program and stuff like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center