English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am having problems creating a window inside a thread. The thread is launched with a funtion from the main application. the LaunchThread() is in a DLL, the DLL also has a function for registering the window using RegisterWindow(), the WndProc and the ThreadProc are also in the DLL.

The thread is created using CreateThread and the ThreadProc calls CreateWindow to create the window, this window will be a user interface for operations that do not interfere with the main application, the window will be launching other threads and such threads will using functions defined in the DLL.

The only connection in between the main application and the DLL is the LaunchThread() function.

//-- Sample code

//-------main application
HANDLE hThread = LaunchThread();


// DLL
HANDLE DLLEXPORT LaunchThread()
{
// Create the theard
}

VOID ThreadProc(LPVOID lParam)
{
// Create the window using CreateWindow

// Message loop in here
}

2006-06-13 17:16:58 · 1 answers · asked by gravit9 2 in Computers & Internet Programming & Design

The HWND returned by CreateWindow() is NULL, but GetLastError() returns 0.

2006-06-13 17:39:04 · update #1

In the previous version of the software I am developing I was using MFC and I created the windows using AfxBeginThread.

I was also able to make it work using a dialog box, but I want to improve the GUI and MFC doesn't cut it, .NET is too much overhead so I opted for SDK.

The idea is that the main application has to process operations that take long , so I have to make the operations in a separate thread, there is a GUI for such operations, that's the reason why the window has to be in a different thread.

The window itself creates more threads from the WndProc, but this is outside the scope of this problem.

All this code goes into a DLL because the entire application is built in modules, so I want its module to have its own GUI.

I know I must be doing wrong and this thing doesn't have enough space to post code.

If I can find a different way to show more code I am willing to even email some code.

2006-06-14 15:29:06 · update #2

1 answers

Can you be more specific? What exactly are the problems you're running into? If you're getting null handles, what do you get when you call GetLastError?

-- EDIT --

>The HWND returned by CreateWindow() is NULL,
> but GetLastError() returns 0.

That is very odd. I'm afraid I can't help debug without seeing more of the code. Some things you might keep in mind:

- GetLastError refers to the last win32 call, so if you're doing anything between the CreateWindow call and GetLastError you could be clobbering your result.

- If your window procedure doesn't handle certain messages, such as WM_CREATE correctly, Bad Things can happen. You should check to see if it's being entered and that messages are being properly routed by your message loop.

- Make sure the hInstance you pass in is for the correct module. You want the library you're using, not the main executable... see updated references for a blog post that may be relevant to you.

- You may want to eliminate the thread as the cause of the problem... if you create this window in the main application thread (ignoring for a moment that this probably doesn't make sense in the context of your app), does the code work then? If so, does it work in a thread in the main application executable (rather than in your library)?

Good luck.

2006-06-13 17:34:52 · answer #1 · answered by Ryan 4 · 1 0

fedest.com, questions and answers