C
Claes Bergefall
I'm trying to call the GetCurrentThread API function
from a managed C++ app, but for some reason it
always returns a null handle?!
And calling GetLastError (or Marshal::GetLastWin32Error) returns
different values depending on where I put the code. For example:
The following is the code that VS generates when selecting
the Windows Forms Application (.NET) project type:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new Form1());
return 0;
}
If I call GetCurrentThreadId before setting ApartmentState I get error 2
(ERROR_FILE_NOT_FOUND). Calling it after gives error 183
(ERROR_ALREADY_EXISTS)
Calling GetCurrentThread from an MFC app (no .NET) or P/Invoking
it from a VB.NET app works just fine.
Perhaps this is some kind of security issue?
I'm doing this on my local machine so there
is no network or related stuff involved.
I'm using .NET 1.1
Any ideas?
/claes
from a managed C++ app, but for some reason it
always returns a null handle?!
And calling GetLastError (or Marshal::GetLastWin32Error) returns
different values depending on where I put the code. For example:
The following is the code that VS generates when selecting
the Windows Forms Application (.NET) project type:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new Form1());
return 0;
}
If I call GetCurrentThreadId before setting ApartmentState I get error 2
(ERROR_FILE_NOT_FOUND). Calling it after gives error 183
(ERROR_ALREADY_EXISTS)
Calling GetCurrentThread from an MFC app (no .NET) or P/Invoking
it from a VB.NET app works just fine.
Perhaps this is some kind of security issue?
I'm doing this on my local machine so there
is no network or related stuff involved.
I'm using .NET 1.1
Any ideas?
/claes