Discussion:
How to Convert I32 to .Net IntPtr?
(too old to reply)
HaD
2008-07-09 09:10:06 UTC
Permalink
I created an .Net Invoke that is linked to "System.Drawing.Image" Class, it convert HBITMAP handle to picture.
I get HBITMAP from other dll through a Windows Message (thats the Lparam in the picture).
 
The problem is that the HBITMAP from the dll is I32 and the .NET require IntPtr type, and i didnt succeded to cast I32 to IntPtr.
 
Please Help,
HaD
 
Image attached


Image1.gif:
Loading Image...
HaD
2008-07-09 14:10:08 UTC
Permalink
Help!
MikeS81
2008-07-09 14:10:10 UTC
Permalink
Hi HaD,
i´m not sure, but maybe it works if you type cast it to the needed type.
 
Hope it helps.Mike
smercurio_fc
2008-07-09 14:40:06 UTC
Permalink
You cannot simply "cast" to a .NET datatype. You must use the proper constructor. In this case you need to use the constructor for IntPtr. Specifically, the one that accepts an integer as an argument:<img src="Loading Image..."> Message Edited by smercurio_fc on 07-09-2008 09:19 AM


Example_VI.png:
http://forums.ni.com/attachments/ni/170/339108/1/Example_VI.png
HaD
2008-07-09 14:40:15 UTC
Permalink
How you got constructor to intptr??? i cant find it.
bc7041
2008-08-03 01:40:17 UTC
Permalink
Dear
&nbsp;
In addition, I can use system.intptr class
And I want to use System.drawing.image class
But, I could not call system.drawing.image in LV(.net)
&nbsp;
Plase inform.
How you got constructor to system.drawing.image class???
&nbsp;
Sincerely yours,
Bongchan Park???? 08-02-2008 08:15 PM? bc7041? ?? ?????
HaD
2008-08-03 04:40:17 UTC
Permalink
I can remember that i created an .Net container and selected ImageBox...&nbsp;Image box has .Image class...
smercurio_fc
2008-08-03 14:40:21 UTC
Permalink
System.Drawing.Image is an abstract class. There are no constructors for it.
bc7041
2008-08-04 00:10:05 UTC
Permalink
Dear Thank for your response.
By the way, I can find system.intptr. But I do't find Image.FromHbitmap method in your attached file.
Please inform method or how
How you got image.formhbitmap ?
&nbsp;
Sincerely yours,
Bongchan Park
smercurio_fc
2008-08-04 15:40:10 UTC
Permalink
bc7041 wrote:I can find system.intptr. Did you follow the directions I gave in reply #6?But I do't find Image.FromHbitmap method in your attached file.
Please inform method or how
How you got image.formhbitmap ?
To whom are you speaking, and what attached file are you referring to? There were no attached files in this thread - only images.
bc7041
2008-08-04 21:40:04 UTC
Permalink
Dear.
In attached file,
No 1 is system.inptr.
No 2 is Image.FromHbitmap method .
Please inform method that I can find it.
Sincerely yours,
Bongchan Park


Example_VI_1.PNG:
Loading Image...
bc7041
2008-08-04 00:10:05 UTC
Permalink
&nbsp;???? 08-03-2008 06:53 PM? bc7041? ?? ?????
smercurio_fc
2008-07-09 16:40:09 UTC
Permalink
- Place a .NET constructor node on the block diagram.
- In the popup dialog select "mscorlib" from the list of assemblies. Make sure you select the right one in case you see more than one depending on how many .NET versions you may have.&nbsp;
- In the "Objects" listbox expand "System".
- Scroll down until you see "IntPtr". Select it.
- In the "Constructors" listbox select the appropriate constructor, which in your case is IntPtr(Int32 value).
- Click OK
- Wire your integer constant to the "value" terminal.
Message Edited by smercurio_fc on 07-09-2008 11:29 AM
HaD
2008-07-09 17:40:09 UTC
Permalink
Thanks!
smercurio_fc
2008-08-04 22:40:05 UTC
Permalink
The second node is a call to a static method, which is what the FromHBitmap method of the Image class is. A static method does not require you create an instance of a class. To call the static method: - Place a .NET Invoke node on the block diagram.
- Right-click on the node and select "Select Class -&gt; .NET -&gt; Browse..."
- In
the popup dialog select "System.Drawing" from the list of assemblies. Make
sure you select the right version in case you see more than one depending
on how many .NET versions you may have installed on your system.&nbsp;
- In the "Objects" listbox expand "System.Drawing".
- Scroll down until you see "Image". Select it.
- Click "OK".
- Left-click on the word "Method" on the node and a popup menu will appear listing all available methods for the Image class. All of the static methods will have "[S]" in front of them. Select the appropriate static method.
Continue reading on narkive:
Loading...