472,978 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,978 software developers and data experts.

Getting an HWND

Hello all,

I have some unmanaged code that requires an HWND to a managed control (e.g.,
a picture box). I try:

mRenderWnd->Handle;

Of course, this returns an IntPtr. If I try to case, I get the error:

Cannot convert a managed type to an unmanaged type

What do I need to do? The whole point of my using managed c++ was to use
the .NET framework for GUI coding and use my existing unmanaged code for the
backend. Some of my functions require HWNDs.
Feb 11 '06 #1
4 1682
>Of course, this returns an IntPtr. If I try to case, I get the error:

Cannot convert a managed type to an unmanaged type

What do I need to do?

Try calling IntPtr::ToPointer first, then cast.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 11 '06 #2
Of course, this returns an IntPtr. If I try to case, I get the error:

Cannot convert a managed type to an unmanaged type

What do I need to do?

Try calling IntPtr::ToPointer first, then cast.


Thanks, I got that error to go away, but now I get this error:

cannot convert parameter 6 from 'cli::interior_ptr<Type>' to
'IDirect3DDevice9 **'
with
[
Type=IDirect3DDevice9 *
]
Cannot convert a managed type to an unmanaged type

This is the call, which is in a method of the Form class:

d3dObject->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
(HWND)hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
d3dPP,
&d3dDevice)); <------problem

As far as I know, this is just unmanaged code calling unmanaged code inside
a managed function. Does this not work?

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Feb 11 '06 #3
d3dObject->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
(HWND)hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
d3dPP,
&d3dDevice)); <------problem


Do you think I need to use pointer pinning? d3dDevice of a pointer to an
unmanaged type. But I think, if I understood some documents I read, the
address of this (i.e., &d3dDevice) will actually evaluate to a __gc pointer.
And I think that is the problem because the unmanaged function CreateDevice
expects a __nogc pointer. I also read that pinning can maybe be used to
convert a managed pointer to an unmanaged pointer.
Feb 11 '06 #4
quat wrote:
Thanks, I got that error to go away, but now I get this error:

cannot convert parameter 6 from 'cli::interior_ptr<Type>' to
'IDirect3DDevice9 **'
[...]
As far as I know, this is just unmanaged code calling unmanaged code inside
a managed function. Does this not work?


Well, cli::interior_ptr is holding a pointer to a managed object. When
the garbage collector re-shuffles the memory, all interior_ptr's are
automatically updated, so they all point to the correct (possibly new)
location. In order to pass a pointer to an unmanaged function, you must
still pin it, to prevent the garbage collector from moving it around,
because unmanaged pointers can't be updated when the managed heap gets
defragmented.

If you're sure that all your types are unmanaged, you may try to move it
to an unmanaged function, and maybe use the #pragma unmanaged directive
to ensure that it's really compiled to native code. I'm not sure why the
compiler believes that your native types are somehow managed.

Tom
Feb 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: hellrazor | last post by:
Hi there, First of all, I'm very much a C++ amateur (i.e., a newb). I'm having to program a win32 system service for my employer, and I'm almost done with the task, but I need help with...
4
by: wallacej | last post by:
I am trying to retrieve a selected value from a listbox and store it in a string (char) variable. I am using the following code: calibIndex=SendMessage(hWnd,(UINT)IDC_LIST_CALIBOPTS,(WPARAM)0,...
5
by: Tedmond | last post by:
Dear all, How can I get all the titles of all openning windows? I found a API in win32 that called EnumWindows() but it returns only the windows handles, not titles. How can I get the list just...
10
by: fotzor | last post by:
Hi, I'm a C++-Programmer and want to subclass the Edit used to write a SQL-Query in Access. The edit is of the special Access class OKttbx. Everything works, I injected a DLL into the...
8
by: Salad | last post by:
I designed a small app and I wanted to do a BrowseFolder (see http://www.mvps.org/access/api/api0002.htm), basically do a file open diaglog and select a directory/folder. The problem is that you...
1
by: | last post by:
I'm trying to get (or set) the focus on an external window but to no avail. I've imported the "GetActiveWindow" and "GetFocus" from the user32.dll but those 2 functions seem to only work for windows...
1
by: eagle | last post by:
How do I get the screen resolution when running an asp.net project. I tried the old way, and I get an error on the apiGetWindowRect that says "Object reference not set to an instance of an object....
2
by: shalender verma | last post by:
Hello All I am using VB 6. I am trying to get the text in the tittle bar of the window i click by using GetWindowText API function but its not working. Here is the code i am using:- Private...
2
by: pangel83 | last post by:
I've been trying for days to write a piece of VB.NET code that will read from winamp's memory space the paths of the files from the current winamp playlist. The GETPLAYLISTFILE command of the...
8
mshmyob
by: mshmyob | last post by:
Is it possible to get the hwnd property (ie: long number) of a control on a form. For instance I would like to get the hwnd property of a text box that has focus. I can get the form hwnd property...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.