COM Interface

Posted By: sheefo

COM Interface - 08/15/07 13:32

I have a working COM DLL, how do I include it in LiteC? Is there a function to include it or a special directory to put it?
Posted By: sheefo

COM Interface @jcl - 08/16/07 13:25

PLEASE! One of the reasons I bought A7 was because I thought it could support COM.

Whether or not my DLL exists I get the same error (80040154). Thats why there must be some way to tell LiteC to use it. How do I include my DLL? The only person I can think of that can answer this is jcl. Please jcl!!!
I have followed the manual exactly (the only difference is I replaced the question marks with the uuid of my class).
Posted By: jcl

Re: COM Interface @jcl - 08/16/07 13:54

You can look up the error number in the VC++ error tool. Maybe you've forgotten to call CoInitialize or something like that, but not knowing what you are doing I can't be of much help, naturally. Writing and implementing COM DLLs requires some experience in C++ programming and debugging.

You can find many examples of include files that implement COM DLLs. For instance, have a look at the d3d9.h file that implements DirectX, and also check out com.h and picture.h for getting the idea.
Posted By: sheefo

Re: COM Interface @jcl - 08/16/07 14:20

Thanks.

I am not understanding whats in picture.h. It's different from the manual.

Here is the definition:
Code:

typedef struct _IObject1Vtbl
{
// IUnknown methods
long __stdcall QueryInterface(long, long riid, void *ppvObject);
long __stdcall AddRef(long);
long __stdcall Release(long);

// IObject1 methods
long __stdcall get_GetANum(long, long* pVal);
} IObject1Vtbl;
typedef interface _IObject1 { IObject1Vtbl *lpVtbl; } IObject1;



This is how I initialize it (just like in the manual):
It returns the error code in the CoCreateInstance function.
Code:

#include <litec.h>
#include <com.h>

IFoo *pIFoo;

int WinMain()
{
HRESULT hr;
hr = CoInitialize(NULL);

GUID CLSID_MyObject;
IID IID_IFoo;


// I DONT KNOW WHAT TO PUT HERE, NO MATTER WHAT I PUT IT DOESN'T WORK:
IIDFromStr("{????????-????-????-????-????????????}",&CLSID_MyObject); // "{8D72F083-9925-4DCE-94E9-CDBD933DDACB}"???


IIDFromStr("{67E3E462-F3C0-48A6-8758-161CEE83D547}",&IID_IFoo);

if (hr!=S_OK)
{
printf("CoInitialize Failed: %x\n\n", hr);
return 0;
}
else
{
printf("CoInitialize succeeded\n");
}



// THIS RETURNS ERROR CODE 80040154
hr = CoCreateInstance(&CLSID_MyObject, NULL, CLSCTX_ALL,&IID_IFoo, &pIFoo);
if (hr!=S_OK)
{
printf("CoCreateInstance Failed: %x\n\n", hr);
}
else
{
printf("CoCreateInstance succeeded\n");
}
CoUninitialize();
}


Posted By: jcl

Re: COM Interface @jcl - 08/16/07 15:22

You must register your class before calling CoCreateInstance. In the manual the "{????????-????-????-????-????????????}" just means 'put your GUID here' - you must not give question marks but a real registered CLSID.

I still don't know what you intend to do but if you've got a COM DLL you should also know its GUIDs and have received instructions or examples about how to bind it to a program. CoCreateInstance and GUIDs are nothing special to lite-C, but standard MFC methods for creating instances of registered classes on your PC.
Posted By: sheefo

Re: COM Interface @jcl - 08/16/07 16:02

How do I register the class and get the CLSID? Do I do this in VC++ or what?

I really appreciate the help, thanks.

BTW, All my DLL does is have a class with one function which sets a variable to a value of 101. I just want to experiment.
Posted By: jcl

Re: COM Interface @jcl - 08/16/07 16:18

When you create the COM DLL with the VC++ Wizard, it's normally registered automatically. Otherwise you need to manually enter it into the registry.

You can read the GUIDS out of the IDL code of your DLL. Alternatively, you can use regedit and search for the name of your project to read the GUIDs out of the registry. You need to know both GUIDs, one for the class (the CLSID) and one for the interface.

However I suggest that you read some literature about the COM model before. This is definitely not beginner's stuff and it makes not much sense to continue if you are not familiar with the basic concepts. I don't know why you need COM, but maybe a plain Win32 DLL will do also? This is easier.
Posted By: sheefo

Re: COM Interface @jcl - 08/16/07 17:26

I guess I got the GUID's right, because I got this: "CoCreateInstance succeeded"

The function executes, but it sets the variable to 1 instead of 101... I wonder why. Anyway, I'll solve it later.

Thank you so much. You are the best! I appreciate your time and help.

PS: I know more about COM than Win32 DLL's (and I know next to nothing about COM). Also, I like classes and this is the only way to use them in LiteC.
© 2023 lite-C Forums