Click here to Skip to main content
15,881,898 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Mixed C++/CLI code with Berkeley DB Pin
anti.AS25-Apr-11 8:34
anti.AS25-Apr-11 8:34 
GeneralRe: Mixed C++/CLI code with Berkeley DB Pin
jschell26-Apr-11 8:05
jschell26-Apr-11 8:05 
GeneralRe: Mixed C++/CLI code with Berkeley DB Pin
anti.AS26-Apr-11 10:20
anti.AS26-Apr-11 10:20 
Questionboost:asio Pin
Alan Kurlansky22-Apr-11 6:42
Alan Kurlansky22-Apr-11 6:42 
AnswerRe: boost:asio Pin
Richard MacCutchan22-Apr-11 22:42
mveRichard MacCutchan22-Apr-11 22:42 
AnswerRe: boost:asio Pin
Albert Holguin28-Apr-11 15:01
professionalAlbert Holguin28-Apr-11 15:01 
QuestionCursor, converting code from vb.net to c++ Pin
Andreoli Carlo21-Apr-11 2:48
professionalAndreoli Carlo21-Apr-11 2:48 
hello i'm trying to convert this piece of code from vb

Private Structure IconInfo
       Public fIcon As Boolean
       Public xHotspot As Int32
       Public yHotspot As Int32
       Public hbmMask As IntPtr
       Public hbmColor As IntPtr
   End Structure

   <DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> _
   Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr
   End Function

   <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
   Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
   End Function

   <DllImport("gdi32.dll")> _
   Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
   End Function

   Public Function CreateCursor(ByVal bmp As Bitmap) As Cursor

       'Setup the Cursors IconInfo
       Dim tmp As New IconInfo
       tmp.xHotspot = _gHotSpotPt.X
       tmp.yHotspot = _gHotSpotPt.Y
       tmp.fIcon = False
       If _gBlackBitBack Then
           tmp.hbmMask = bmp.GetHbitmap(Color.FromArgb(0, 0, 0, 0))
           tmp.hbmColor = bmp.GetHbitmap(Color.FromArgb(0, 0, 0, 0))
       Else
           tmp.hbmMask = bmp.GetHbitmap()
           tmp.hbmColor = bmp.GetHbitmap()
       End If

       'Create the Pointer for the Cursor Icon
       Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp))
       Marshal.StructureToPtr(tmp, pnt, True)
       Dim curPtr As IntPtr = CreateIconIndirect(pnt)

       'Save the image of the cursor with the _gBlackBitBack effect
       'Not really needed for normal use.
       'I use it to create a screen shot with the gCursor included
       _gCursorImage = Icon.FromHandle(curPtr).ToBitmap

       'Clean Up
       DestroyIcon(pnt)
       DeleteObject(tmp.hbmMask)
       DeleteObject(tmp.hbmColor)

       Return New Cursor(curPtr)
   End Function

By now i traslate the all thing into:

public struct IconInfo
	{
		bool fIcon;
		int xHotspot;
		int yHotspot;
		System::IntPtr hbmMask;
		System::IntPtr hbmColor;
	};

	[System::Runtime::InteropServices::DllImport("user32.dll, EntryPoint:=CreateIconIndirect")]
	System::IntPtr CreateIconIndirect(System::IntPtr iconInfo);

	[System::Runtime::InteropServices::DllImport("user32.dll, CharSet:=CharSet.Auto")]
	bool  DestroyIcon(System::IntPtr handle);

	[System::Runtime::InteropServices::DllImport("gdi32.dll")]
	bool DeleteObject(System::IntPtr handl);

System::Windows::Forms::Cursor ^CreateCursor(Bitmap ^bmp, int xHotSpot, int yHotSpot)
			{
				
				// Setup the Cursors IconInfo
				IconInfo tmp;
				tmp.xHotspot = 3;
				tmp.yHotspot = 3;
				tmp.fIcon = false;
				bool _gBlackBitBack=false;
				if (_gBlackBitBack) {
					tmp.hbmMask = bmp->GetHbitmap(Color::FromArgb(0, 0, 0, 0));
					tmp.hbmColor = bmp->GetHbitmap(Color::FromArgb(0, 0, 0, 0));
				}
				else {
					tmp.hbmMask = bmp->GetHbitmap();
					tmp.hbmColor = bmp->GetHbitmap();
				}

				// Create the Pointer for the Cursor Icon
				IntPtr pnt= Marshal::AllocHGlobal(Marshal::SizeOf(tmp));
				Marshal::StructureToPtr(%tmp, pnt, true);
				
				IntPtr curPtr = CreateIconIndirect(pnt);

				// Clean Up
				DestroyIcon(pnt);
				DeleteObject(tmp.hbmMask);
				DeleteObject(tmp.hbmColor);

				
				return gcnew System::Windows::Forms::Cursor(curPtr);
			}

the problem is that i get the following error and i don't know how to get it solved:

error C2665: 'System::Runtime::InteropServices::Marshal::SizeOf' : none of the 2 overloads could convert all the argument types
1> c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll: could be 'int System::Runtime::InteropServices::Marshal::SizeOf(System::Object ^)'
1> c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll: or 'int System::Runtime::InteropServices::Marshal::SizeOf(System::Type ^)'
1> while trying to match the argument list '(test_cursor::IconInfo)'
error C2664: 'System::Runtime::InteropServices::Marshal::StructureToPtr' : cannot convert parameter 1 from 'test_cursor::IconInfo' to 'System::Object ^'
1> No user-defined-conversion operator available, or
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
AnswerRe: Cursor, converting code from vb.net to c++ Pin
Andreoli Carlo21-Apr-11 3:13
professionalAndreoli Carlo21-Apr-11 3:13 
QuestionDeployment of Managed C++ application Pin
pix_programmer14-Apr-11 20:55
pix_programmer14-Apr-11 20:55 
Questioncreating new instance using com smart pointer fails Pin
Dhadhan13-Apr-11 18:18
Dhadhan13-Apr-11 18:18 
AnswerRe: creating new instance using com smart pointer fails Repost Pin
Richard MacCutchan13-Apr-11 22:20
mveRichard MacCutchan13-Apr-11 22:20 
QuestionSounds in .Net. How? Pin
Cyclone_S2-Apr-11 13:26
Cyclone_S2-Apr-11 13:26 
AnswerRe: Sounds in .Net. How? Pin
Richard Andrew x642-Apr-11 16:02
professionalRichard Andrew x642-Apr-11 16:02 
QuestionAny update on Intellisense for C++/CLI in VS2010 Pin
Ger Hayden1-Apr-11 8:44
Ger Hayden1-Apr-11 8:44 
AnswerRe: Any update on Intellisense for C++/CLI in VS2010 Pin
John Schroedl2-Apr-11 13:46
professionalJohn Schroedl2-Apr-11 13:46 
GeneralRe: Any update on Intellisense for C++/CLI in VS2010 Pin
T21026-Apr-11 17:29
T21026-Apr-11 17:29 
QuestionAnimating a snake (aka Snafu) [modified] Pin
Cyclone_S25-Mar-11 14:20
Cyclone_S25-Mar-11 14:20 
AnswerRe: Animating a snake (aka Snafu) Pin
Richard Andrew x6425-Mar-11 14:40
professionalRichard Andrew x6425-Mar-11 14:40 
GeneralRe: Animating a snake (aka Snafu) Pin
Cyclone_S25-Mar-11 14:54
Cyclone_S25-Mar-11 14:54 
GeneralRe: Animating a snake (aka Snafu) Pin
Richard Andrew x6425-Mar-11 14:57
professionalRichard Andrew x6425-Mar-11 14:57 
GeneralRe: Animating a snake (aka Snafu) Pin
Cyclone_S26-Mar-11 13:09
Cyclone_S26-Mar-11 13:09 
GeneralRe: Animating a snake (aka Snafu) Pin
Richard Andrew x6426-Mar-11 13:50
professionalRichard Andrew x6426-Mar-11 13:50 
GeneralRe: Animating a snake (aka Snafu) Pin
Cyclone_S27-Mar-11 13:27
Cyclone_S27-Mar-11 13:27 
GeneralRe: Animating a snake (aka Snafu) Pin
Richard Andrew x6427-Mar-11 14:12
professionalRichard Andrew x6427-Mar-11 14:12 
GeneralRe: Animating a snake (aka Snafu) Pin
Cyclone_S27-Mar-11 14:25
Cyclone_S27-Mar-11 14:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.