|
-
Sep 22nd, 2011, 06:19 PM
#1
Thread Starter
Lively Member
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
-
Sep 22nd, 2011, 06:57 PM
#2
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
-
Sep 24th, 2011, 10:14 AM
#3
Thread Starter
Lively Member
Re: VB port from C++
 Originally Posted by Nightwalker83
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);
?
-
Sep 24th, 2011, 10:29 AM
#4
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
-
Sep 24th, 2011, 10:39 AM
#5
Thread Starter
Lively Member
Re: VB port from C++
 Originally Posted by LaVolpe
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?
-
Sep 24th, 2011, 10:46 AM
#6
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.
-
Sep 24th, 2011, 11:13 AM
#7
Thread Starter
Lively Member
Re: VB port from C++
 Originally Posted by LaVolpe
Not much experience at all with what you are attempting to do.
Unfortunatelly me too! 
 Originally Posted by LaVolpe
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. 
 Originally Posted by LaVolpe
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?
-
Sep 24th, 2011, 11:18 AM
#8
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
-
Sep 25th, 2011, 01:15 PM
#9
Thread Starter
Lively Member
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.
-
Oct 1st, 2011, 11:08 AM
#10
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|