Undefined (Win32) Externals

Loopback elliott.darfink at gmail.com
Sun Jun 12 16:37:57 PDT 2011


On 2011-06-13 01:16, Jonathan M Davis wrote:
> On 2011-06-12 15:39, Loopback wrote:
>> Hi!
>>
>> Let me begin by saying, that I haven't used Usenet newsgroup at all, so
>> please excuse me for any errors or misunderstandings of the guidelines.
>>
>> I recently begun programming a win32 application though I instantly got
>> stuck with a problem. As you might know, win32 applications require that
>> you define the WindowProc function for processing window messages.
>>
>> I've used a object-oriented approach for this, and that requires that
>> you declare the WindowProc function as static, and bind your own class
>> (hWnd) to GWL_USERDATA, to be able to call your own, class defined,
>> message handler (WindowProc). To do this, you have to access the two
>> functions GetWindowLong and SetWindowLong.
>>
>> For some reason, these functions do not exist in the windows module
>> (std.c.windows.windows), neither does the GWL_USERDATA constant.
>>
>> To solve this I've used this alternative code:
>>
>> extern (Windows)
>> {
>> 	int GWL_USERDATA;
>> 	LONG SetWindowLong(HWND, int, LONG);
>> 	LONG GetWindowLong(HWND, int);
>> }
>>
>> When I then try to compile this application, the GWL_USERDATA constant
>> compiles without any errors, but the Get-/SetWindowLong produces linker
>> errors.
>>
>> To solve the linker errors, I checked which library they were contained
>> in, on MSDN it said User32.lib. Therefore I linked to this library -
>> without any success.
>>
>> So to summarize, how do I solve these linker errors:
>>
>> Error 42: Symbol Undefined _SetWindowLong at 12
>> Error 42: Symbol Undefined _GetWindowLong at 8
>>
>> Sorry for such a long message!
>> Any help is greatly appreciated!
>
> I believe that you need extern(C) around those functions. They're C functions,
> not D functions.
>
> - Jonathan M Davis
Thanks for you reply though linker errors (Symbol Undefined) are still 
generated even though I've specified the functions as external C.


More information about the Digitalmars-d mailing list