Help Me! Thank you very much!
-
Hi, friends I tried to build a dll which support COM self-regist using Visual C++ 6.0. I used a API, named LoadTypeLib, to load the dll's typelib: ... CComPtr pTypeLib; HRESULT result = LoadTypeLib(module,&pTypeLib); ... The variable "module" is the DLL's full path name. For example, I use "D:\\temp\\test\\test.dll". But, the return value "result" always is 0x80029c4a (TYPE_E_CANTLOADLIBRARY). If I use "D:\\temp\\test\\test.tlb" as the value of "module", this function should return 0x00000000(S_OK). I have import "test.tlb" into the resource of test.dll. So I don't know how to resolve this problem. Thanks a lot! smalldemon
-
Hi, friends I tried to build a dll which support COM self-regist using Visual C++ 6.0. I used a API, named LoadTypeLib, to load the dll's typelib: ... CComPtr pTypeLib; HRESULT result = LoadTypeLib(module,&pTypeLib); ... The variable "module" is the DLL's full path name. For example, I use "D:\\temp\\test\\test.dll". But, the return value "result" always is 0x80029c4a (TYPE_E_CANTLOADLIBRARY). If I use "D:\\temp\\test\\test.tlb" as the value of "module", this function should return 0x00000000(S_OK). I have import "test.tlb" into the resource of test.dll. So I don't know how to resolve this problem. Thanks a lot! smalldemon
Hello smallbluedemon, 1. Make sure that you have set the resource type to be "TYPELIB" and have also set the resource ID to be 1. 2. Try out the following function to load your resource-embedded type library binary : HRESULT MyLoadTypeLibrary(ITypeLib** ppITypeLibReceiver) { TCHAR szFileName[_MAX_PATH]; memset (szFileName, 0, sizeof(szFileName)); GetModuleFileName ( (HMODULE)NULL, (LPTSTR)szFileName, (DWORD)sizeof(szFileName) ); // Need to concatenate a \1 to the end of the filename // because we are acquiring the type library which is // embedded as the 1st resource of type TYPELIB. strcat (szFileName, "\\1"); return LoadTypeLib((const OLECHAR FAR*)_bstr_t(szFileName), ppITypeLibReceiver); } Use it in your code this way : int main(int argc, char* argv[]) { CComPtr pTypeLib; MyLoadTypeLibrary(&pTypeLib); return 0; } Pls let me know how things go :-) Best Regards, Bio.
-
Hello smallbluedemon, 1. Make sure that you have set the resource type to be "TYPELIB" and have also set the resource ID to be 1. 2. Try out the following function to load your resource-embedded type library binary : HRESULT MyLoadTypeLibrary(ITypeLib** ppITypeLibReceiver) { TCHAR szFileName[_MAX_PATH]; memset (szFileName, 0, sizeof(szFileName)); GetModuleFileName ( (HMODULE)NULL, (LPTSTR)szFileName, (DWORD)sizeof(szFileName) ); // Need to concatenate a \1 to the end of the filename // because we are acquiring the type library which is // embedded as the 1st resource of type TYPELIB. strcat (szFileName, "\\1"); return LoadTypeLib((const OLECHAR FAR*)_bstr_t(szFileName), ppITypeLibReceiver); } Use it in your code this way : int main(int argc, char* argv[]) { CComPtr pTypeLib; MyLoadTypeLibrary(&pTypeLib); return 0; } Pls let me know how things go :-) Best Regards, Bio.
Hello, Bio. Thank you very much! By your suggestion, I found my mistakes. In my resource header file "resource.h", I set following macro: #define IDR_TYPELIB 199 But, I forgot to add this to file name. I add your statement: ........ GetModuleFileName(hInstance, ansiPath, MAX_PATH); strcat(ansiPath,"\\199"); MultiByteToWideChar(CP_ACP, 0, ansiPath, strlen(ansiPath) + 1,module, MAX_PATH); ....... Problem resolved ! Thank you again. Thank you very much! Your sincerely Remy (smallbluedemon)
-
Hello, Bio. Thank you very much! By your suggestion, I found my mistakes. In my resource header file "resource.h", I set following macro: #define IDR_TYPELIB 199 But, I forgot to add this to file name. I add your statement: ........ GetModuleFileName(hInstance, ansiPath, MAX_PATH); strcat(ansiPath,"\\199"); MultiByteToWideChar(CP_ACP, 0, ansiPath, strlen(ansiPath) + 1,module, MAX_PATH); ....... Problem resolved ! Thank you again. Thank you very much! Your sincerely Remy (smallbluedemon)
Hello Remy, That's great ! You are most welcome, Remy. Best Regards, Bio.