Calling a VB DLL w/ forms from C++ DLL

This is a discussion on Calling a VB DLL w/ forms from C++ DLL within the C++ Programming forums, part of the General Programming Boards category; Hi, I've written a C++ DLL which calls an activex dll (the activex dll loads a progress bar/form). However, the ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    8

    Calling a VB DLL w/ forms from C++ DLL

    Hi,

    I've written a C++ DLL which calls an activex dll (the activex dll loads a progress bar/form). However, the progress bar/form does not appear in the task bar when it is called by the C++ DLL. It can only be seen if everything is minimized revealing just the desktop (and progress bar). For example, I cannot alt-tab to the progress bar/form.

    Is there any explanation for this?? Or am I overlooking smoething very obvious?

    Also, i've sent my app (well what's working as of the moment) to a client computer. I've just sent the exe, C++ DLL and VB6 DLL <-the progress bar. Everything in the C++ DLL runs perfect but the progress bar doesn't even pop up!! (even though it's supposed to be called by C++ DLL). I've registered both DLLs also and placed them in the correct directories corresponding to those specified when i compiled the exe on my own computer.

    Thanks.

    RYAN

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    I, too, have tried to call VB DLLs from C apps to no avail. It is not easy to mix these two languages w/o the aid of .NET architecture - something which I'm dying to try out. Perhaps the bar/form object is not recognized by the C compiler when you compile.

    You might have a resource problem or perhaps your C program is obtaining garbage back from the VB 6 DLL. Again, I would not advise mixing these unless you have a 3rd party software program that clears up the confusion in the data structures between the two languages.

    My uncle's company was going to take this route as well but had similar problems (could not return an object from VB to C - all the strings were trashed). They decided to code the entire program in VB and forget C. I'm not saying you should do this, but it might save you a lot of headaches.

    My advice to you is to create your own progress bar in a C resource compiler and then write the code for the resource - load that instead of trying to port a resource from VB to C. MFC may even have a class specifically for progress bars which would save you a lot of time - I'm not completely familiar with MFC but I'm sure it has a class for this.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    8

    Showing the form.

    The only way that I am able to show the form is by using "vbmodal" as one of the parameters for "form.show". However, this is why it does not appear in the taskbar! Is there a way to allow it to be MODELESS and still show up when called from C++?

    Thanks.

    Ryan

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Not sure - check your VB6 documentation for the different styles of forms. Does the program run ok from pure VB - in other words - having a VB app load and/or show the VB form with Form.Show().
    The problem might actually be in your VB code and have nothing to do with C. Since you are not really passing any object back and forth between C and VB, the form loading/showing is being taken care of by the DLL. This would point to a problem in the VB app since all the C app does is use the function in the DLL that loads/shows the form.

    Also check out MS's knowledge base on their developer forum. They have a wealth of information, albeit hard to sift through in a single day.

    If I remember correctly there is a way to show a form as modeless, but I'm not sure if it would show up in the task bar. Try it with a dialog box and see. Most dialog boxes also do not show up on the task bar.

    Why do you need this loading window to show up in the task bar? If you start your C app, call the DLL and load/show the VB form, the C app should show up in the task bar. Since the form is basically running inside of the whole program I don't think it would be treated as a separate program - unless you start a thread - which is another idea. Perhaps you need to create a thread for your progress bar - that should show up in the taskbar if you create it correctly. Let me do some research in my SDK and VB6 docs.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    8

    Another Thread.

    Yeah..
    basically it's a thread i've written in C++ which calls a subroutine, within a class module in the VB Activex DLL. THis subroutine than loads and shows the form 'vbmodally' in the DLL.

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    There's link on MSDN about mixing C and VB somewhere (sorry I dont have the link)

    The way I would do this is to create the dll part as an ActiveX component. Then use MFC to load the typelib of the VB app. This will allow MFC to create wrapper classes around your VB classes so you can use them like any other C++ object.

    Oh...VB uses BSTR for strings....like unicode strings in C++, but they dont need to be NULLed as the 2 bytes before the string holds the size of the string

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    8

    Could you Explain this?

    "The way I would do this is to create the dll part as an ActiveX component. Then use MFC to load the typelib of the VB app. This will allow MFC to create wrapper classes around your VB classes so you can use them like any other C++ object."

    what do you mean by using MFC to load the typelib?

    Is there any documentation floating around that would be able to help me?

    Thanks.

    Ryan

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Look at your VC++ docs....I havent done it for a while and I dont have VC++ at hand, but if I remember rightly, you can tell classwizard to create classes from a typelib

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    8

    How bout an exe??

    Would the forms be shown modelessly if I had compiled a VB exe instead, and called it from C++??

    If i were to do this, would i be able to pass data to the function in the exe and also get values returned from it??

    Thanks.

    Ryan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling a DLL
    By jamez05 in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2006, 11:13 AM
  2. Passing an Array of Strings from VB to a C DLL
    By mr_nice! in forum Windows Programming
    Replies: 9
    Last Post: 03-08-2005, 06:16 AM
  3. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  4. calling exe from in a Dll? Help the poor VB guy!
    By nmessick in forum C++ Programming
    Replies: 5
    Last Post: 09-16-2002, 03:01 PM
  5. Calling C++ DLL from Excel VB...!
    By Tony in forum Windows Programming
    Replies: 0
    Last Post: 06-26-2002, 09:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21