Results 1 to 10 of 10

Thread: VB port from C++

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    95

    Question VB port from C++

    Hey guys, is it possible to port following code to VB6:

    HTML Code:
    HRESULT __stdcall MyCoCreateInstance(
      LPCTSTR szDllName,
      IN REFCLSID rclsid,
      IUnknown* pUnkOuter,
      IN REFIID riid,
      OUT LPVOID FAR* ppv)
    {
      HRESULT hr = REGDB_E_KEYMISSING;
    
      HMODULE hDll = ::LoadLibrary(szDllName);
      if (hDll == 0)
        return hr;
    
      typedef HRESULT (__stdcall *pDllGetClassObject)(IN REFCLSID rclsid, 
                       IN REFIID riid, OUT LPVOID FAR* ppv);
    
      pDllGetClassObject GetClassObject = 
         (pDllGetClassObject)::GetProcAddress(hDll, "DllGetClassObject");
      if (GetClassObject == 0)
      {
        ::FreeLibrary(hDll);
        return hr;
      }
    
      IClassFactory *pIFactory;
    
      hr = GetClassObject(rclsid, IID_IClassFactory, (LPVOID *)&pIFactory);
    
      if (!SUCCEEDED(hr))
        return hr;
    
      hr = pIFactory->CreateInstance(pUnkOuter, riid, ppv);
      pIFactory->Release();
    
      return hr;
    }
    I am struggling with the harder calls in that routine.
    If there is a C++ pro here, then please give me some advice.


    PS, the code is from here:
    http://www.codeproject.com/KB/COM/Em...eInstance.aspx

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: VB port from C++

    I think it is however, it would be time consuming and in any case a waste because VB6 is 13 years old. VB.NET would be better choice to convert to because you would only have to convert across languages, not down and across. Up or down refers to the change in framework (.NET, COM, etc).
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    95

    Re: VB port from C++

    Quote Originally Posted by Nightwalker83 View Post
    I think it is however, it would be time consuming and in any case a waste because VB6 is 13 years old. VB.NET would be better choice to convert to because you would only have to convert across languages, not down and across. Up or down refers to the change in framework (.NET, COM, etc).
    Ok, but I need it for VB6.

    How can following line ported:
    Code:
    typedef HRESULT (__stdcall *pDllGetClassObject)(IN REFCLSID rclsid, IN REFIID riid, OUT LPVOID FAR* ppv);
    ?

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB port from C++

    Here are some untested ideas...

    1. Use CoCreateInstance/CoCreateInstanceEx APIs. Search for examples

    2. Use VB's CreateObject function. Since VB wants a ProgID instead of a CLSID, if you have the CLSID then you can convert it to ProgID with the ProgIDFromCLSID API
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    95

    Re: VB port from C++

    Quote Originally Posted by LaVolpe View Post
    Here are some untested ideas...
    Hello LaVolpe, thank you for your suggestion.

    Your idea will work - it is the way which I like to replace.

    The CLSID is only available for a registered class.
    - But I like to find a way, to to created an object from an unregistered class. Can this be done somehow similar to the code posted in my first comment?

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB port from C++

    Not much experience at all with what you are attempting to do.

    If you can create an IClassFactory instance (registered class I believe) using discussed methods, then you might then be able to call DLLGetClassObject API

    Edited: As far as testing if DllGetClassObject is supported in the dll, the same logic can be used nearly identically in VB6: LoadLibrary, GetProcAddress & FreeLibrary API calls.
    Last edited by LaVolpe; Sep 24th, 2011 at 10:53 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    95

    Re: VB port from C++

    Quote Originally Posted by LaVolpe View Post
    Not much experience at all with what you are attempting to do.
    Unfortunatelly me too!

    Quote Originally Posted by LaVolpe View Post
    If you can create an IClassFactory instance (registered class I believe) using discussed methods, then you might then be able to call DLLGetClassObject API
    What is this IClassFactory? How can I declare it?
    You are talking about an instance. Can interfaces really be instanciated?
    As far as I know, a factory is a procedural approach... ok, maybe internally an interface is also just an object.

    I have already problems to get the pointer to that IClassFactory.
    What to pass to following call:
    Code:
    hr = GetClassObject(rclsid, IID_IClassFactory, (LPVOID *)&pIFactory);
    ?

    Is rclsid important? How can I get it?

    For IID_IClassFactory I just found that:
    Code:
    Private Const IID_IClassFactory As String = "00000001-0000-0000-C000-000000000046"
    But this is the wrong type! If I use zero instaed, my programm crashes.

    Quote Originally Posted by LaVolpe View Post
    Edited: As far as testing if DllGetClassObject is supported in the dll, the same logic can be used nearly identically in VB6: LoadLibrary, GetProcAddress & FreeLibrary API calls.
    Ok, sounds good. Do you think there is still hope for me?

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB port from C++

    Here is a very good link that may contain what you need or, at the very least, clues to what you may need.

    Note that it primarily discusses how to create a VB6 DLL that can be called like a standard windows dll. You will need an account to download attachments. So if no account exists, register on that site

    The specific link I'm talking about is in the 1st post and is a pdf
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    95

    Re: VB port from C++

    You are AWESOME LaVolpe!!! - That project is a gem!

    I'll bet I can use this technique in future. For my current problem I am not sure... - if I can use it, then I am just one step further:
    I like to emulate CoCreateInstance with a techique, that does not depend on a registered class. This is needed for the multithreading project, which I did suggest you lately. In this project a dummy object has to be created. This is working fine on my system - but on others not. Even if the dll is registered correctly there. That is why I like to come away from the COM thing.

    Do you know any other way to create an object like CoCreateInstance does - but which can do it without using COM?
    Last edited by NeedHelp!; Sep 25th, 2011 at 02:00 PM.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    95

    Re: VB port from C++

    I found another project, which looks pretty good:
    http://foren.activevb.de/cgi-bin/for...ge=1&root=1201

    The project itself works. But I am getting crashes, if I use it in the multithreading project. - Maybe I doing something wrong:
    Code:
        'instead of this call:
        'hR = CoCreateInstance(NewThreadInfo.classid, Nothing, CLSCTX_INPROC_SERVER, IID_IUnknown, pUnk)
        'I am using following line now:
        Set pUnk = CreateObjectFromFile(App.Path & "\DummyLib.dll", "DummyClass")
    Can anybody see the problem?

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