Windows parameter
David
d at dav1d.de
Sun Jun 30 15:43:57 PDT 2013
Am 30.06.2013 22:20, schrieb shuji:
> On Sunday, 30 June 2013 at 20:04:12 UTC, Anthony Goins wrote:
>> On Sunday, 30 June 2013 at 19:03:13 UTC, shuji wrote:
>>> this code is in a .cpp file
>>> //funcs.lib
>>> //windows includes...
>>> HWND hwnd;
>>> int setHWND(HWND extHwnd){
>>> hwnd = extHwnd;
>>> return 0;
>>> }
>>>
>>> So im trying to import from D like this. I dont think I can implement
>>> this line in C++
>>> extern (C++) {}
>>
>> I'm probably the most unqualified person to offer help but are you
>> sure you are linking with funcs.lib (assuming setHWND is defined there)
>
> yes, i have called other functions in the same file correctly.
>
> PD I can call a function with void* as receiving paremeter:
> //main.d
> extern (C++) {
> int setHWND(void* ehwnd);
> }
> //mylib.cpp
> int setmyHWND(void* exthwnd){
> hwnd = (HWND)exthwnd;
> return 0;
> }
> and then cast on C++ to HWND, but I think it would be better to send the
> parameter correctly as HWND.
make sure the HWND parameter is on both "sides" the same (it has to get
mangled correctly!). I don't know if HWND is an opaque struct, if it is,
this might get you into trouble.
--- Cut here, I looked into core.sys.windows.windows:
---
alias void *HANDLE;
alias HANDLE HWND;
---
That is the problem, on the C++-Side HWND is not of type void* hence it
gets mangled differently, you need to get DMD mangle it the same as the
C++ compiler does...
The problem is (I just looked it up) HWND is *basically* void*
All typedefs:
PVOID = void*
HANDLE = PVOID
HWND = HANDLE
So you have to "emulate" a typedef to get the correct mangling... Maybe
start messing arround with structs?
struct HWND;
etc.
Maybe you could also try to use the deprecated "typedef" in D. Neither
of these soloutions are really great. I would consider this another bug
on the extern(C++) list.
More information about the Digitalmars-d-learn
mailing list