The same code is running perfectly when i use it in different exe or
dl..
Thanks,
J
Where do you call CoInitialize? I don't think the system makes any
promises about which thread is used to call your hook callback.
>The problem is that the CoCreateInstance fails with error 1008.
>Please tell me what is happening.
That would be ERROR_NO_TOKEN, but that's not the usual format of a COM
error. What object are you trying to create? Can you show us the code you
used to create the object, and the code that displays the error number?
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
CoInitialize(NULL);
IShellWindows *psw;
//AfxMessageBox(L"Reached here1");
if (SUCCEEDED(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL,
IID_IShellWindows, (void**)&psw)))
AfxMessageBox(L"Pass");
else{
CString str;
str.Format(L"%d",GetLastError());
AfxMessageBox(str);
}
Well one problem that you definitely have is calling GetLastError following
CoCreateInstsance - there's absolutely no guarantee that GetLastError
returns anything even remotely related to the COM error. Instead, you need
to hold onto the HRESULT returned by CoCreateInstance and examine that to
determine why the call is failing.
-cd
Thanks,
The value in the HRESULT is - "Failed to allocate necessary memory"
This problem only occurs within the hook function. Any other function
in the same dll i put this code it is works just fine.
Any security reasons??
Regards,
J
Well, it's a very bad idea (i.e. will fail or cause other failures randomly)
to call CoInitialize from a hook function. Maybe that thread was using COM
with different settings. If the application already called CoInitialize,
your options will be ignored and if they chose a different apartment model
your CoCreateInstance call will fail. If your call to CoInitialize comes
first, then the application settings will be ignored and the app may be
unable to use its own COM objects. A very bad situation either way.
Instead, use one of the many IPC methods to move the data to a thread you
control and do the COM interaction there.
>
> Regards,
> J
>
>
I found that the problem occurs only when i try to create an object of
IShellWindows all other interfaces are working perfectly.
"JoDeGr8" <johne...@gmail.com> wrote in message
news:eae0d1cc-8e21-43c5...@v20g2000yqm.googlegroups.com...
No, it won't. You can call CoInitialize as many times as you want from a
thread - only the first such call has any effect other than to increase the
success count. If you've called CoInitialize 'n' times, you must also call
CoUninitialize 'n' times.
http://msdn.microsoft.com/en-us/library/ms678543(VS.85).aspx
-cd
"Carl Daniel [VC++ MVP]" <cpdaniel_remove...@mvps.org.nospam>
wrote in message news:uJcUirmI...@TK2MSFTNGP04.phx.gbl...
http://msdn.microsoft.com/en-us/library/ms695279(VS.85).aspx
CoInitializeEx must be called at least once, and is usually called only
once, for each thread that uses the COM library.
"Carl Daniel [VC++ MVP]" <cpdaniel_remove...@mvps.org.nospam>
wrote in message news:uJcUirmI...@TK2MSFTNGP04.phx.gbl...