Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating a window, getting HINSTANCE

278 views
Skip to first unread message

Michael Gade

unread,
Aug 19, 2002, 4:00:17 PM8/19/02
to
Hi
I have a fully working DLL that I want to expand so that it can create a
simple window via CreateWindowEx,
and add text to that window, all by using the cmd-line tool.
However when I run the DLL the window doesn't get created, maybe it is
because hInstance is null.
So is it possible to get a HINSTANCE, is there something like
getHINSTANCE??? Here is the code:

HINSTANCE hInstance;
HWND hWindow;

hWindow = CreateWindowEx(0, //more or
'extended' styles
TEXT("ERR"), //the 'class'
of window to create
TEXT("Simple Window"), //the window
title
WS_OVERLAPPEDWINDOW, //window
style: how it looks
GetSystemMetrics(SM_CXSCREEN)/4, //window
position: left
GetSystemMetrics(SM_CYSCREEN)/4, //window
position: top
GetSystemMetrics(SM_CXSCREEN)/2, //window
width
GetSystemMetrics(SM_CYSCREEN)/2, //window
height
NULL, //parent
window handle
NULL, //handle to
this windows's menu
hInstance, //application
instance
NULL); //user
defined information

if (!hWindow)
dialogBox("Failed to create wnd");

ShowWindow(hWindow, 1);
UpdateWindow(hWindow);

/Michael


Hates Spam@ga.prestige.net SleazySt

unread,
Aug 20, 2002, 8:58:34 AM8/20/02
to
hInstance = GetModuleHandle(NULL);

"Michael Gade" <mgn5...@stud.auc.dk> wrote in message
news:3d614eae$0$94829$edfa...@dspool01.news.tele.dk...

r_z_...@pen_fact.com

unread,
Aug 20, 2002, 9:03:36 AM8/20/02
to
I _think_ you shouldn't need an HINSTANCE to open a window, unless you
are trying to use resources in a file, but I have never tried. I know
you need an HINSTANCE if you want to load resources.

If you want to get the HINSTANCE for the current process (the .exe
that started the program), you have two choices:
a) Keep the value passed to WinMain
b) Call GetModuleHandle, and pass NULL as the argument. The
documentation for the function says it returns an HMODULE, but I
believe the values are the same (so a cast will work).

If you want to get the HINSTANCE for the DLL, you have three choices:
a) Keep the value passed to DllMain
b) Keep the value returned by LoadLibrary
c) Call LoadLibrary to get the return value, then call FreeLibrary
I've never used the last method, so I can 't vouch directly. But it
makes sense.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret
PenFact, Inc.
46 Beach Street
Boston, MA 02111
www.penfact.com

0 new messages