|
Hi,
I am porting my vc2003 app to vc2008 and have come across somthing like this...
LPCTSTR lpsz = _T("myString");
SomeObject *obj = Afunc( lpsz );
under vc2003 this compiles and works file however in vc2008 it seems that i need to do...
LPCTSTR lpsz = _T("myString");
SomeObject ^obj = Afunc( gcnew String(lpsz) );
the documentation on string literals in C++/CLI migration primer suggest that the following could be done.
SomeObject ^obj = AFunc( safe_cast<string^>(lpsz) );
this is wrong as it not compile.
I not sure the gcnew string( lpsz ) method is ideal. is there a better way or what is the propper way of doing this.
thanks
Robin
|
|
|
|
|
Robin Imrie wrote: I not sure the gcnew string( lpsz ) method is ideal. is there a better way or what is the propper way of doing this.
in general gcnew is how you create managed objects in C++/CLI so that is always a correct way to do it. Of course strings can be different like in Native C++ based on what you need them for. In your code you are creating a native string and then converting it to a managed string.
If you only need a managed string then you could do this.
System::String^ lpsz = "myString";
There is a series of introductory C++/CLI articles here on CodeProject. I suggest you take advantage of them.
led mike
|
|
|
|
|
Thanks mike for that i had suspected as much.
Will give the C++/CLI articles a good look.
|
|
|
|
|
Hi all,
We installed gtk from the following site
http://crossfire.real-time.com/clients/win32_gtk.html
please help us how to compile and run our own c++ files
Thank You
Sesha Sridhar
|
|
|
|
|
Hi to all,
I have an 'Windows Form Control Library' "VideoWindow.dll" in VC#.Net 2008, having code as following,
<block><br />
using DirectShowLib;
<br />
<br />
public partial class VideoWindow : UserControl<br />
{<br />
public VideoWindow()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
Label m_picVideoWindow = new Label();<br />
<br />
public int SetPreview(IVideoWindow vwRenderer)<br />
{<br />
int hr = 0;<br />
if (m_picVideoWindow.Bounds.IsEmpty)<br />
return hr;<br />
try<br />
{<br />
hr = vwRenderer.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings);<br />
DsError.ThrowExceptionForHR(hr);<br />
hr = vwRenderer.put_Owner(m_picVideoWindow.Handle);<br />
DsError.ThrowExceptionForHR(hr);<br />
hr = vwRenderer.SetWindowPosition(0, 0, m_picVideoWindow.Width, m_picVideoWindow.Height);<br />
DsError.ThrowExceptionForHR(hr);<br />
hr = vwRenderer.put_Visible(OABool.True);<br />
DsError.ThrowExceptionForHR(hr);<br />
}<br />
catch (Exception ex)<br />
{<br />
}<br />
return hr;<br />
}<br />
}<br />
</block>
When I am calling SetPreview() from my VC++.Net 2008 MFC Application as follows,
<block><br />
IVideoWindow *pWidnow;
CWinFormsControl<VideoWindow::VideoWindow> *a1 = new CWinFormsControl<VideoWindow::VideoWindow>();<br />
<br />
(*a1)->SetPreview(pWidnow);<br />
</block>
It gives compile error as,
error C2664: 'VideoWindow::VideoWindow::SetPreview' : cannot convert parameter 1 from 'IVideoWindow *' to 'DirectShowLib::IVideoWindow ^'
Please help me to solve this error.
Regards,
Aniket A. Salunkhe
|
|
|
|
|
Aniket Salunkhe wrote: Please help me to solve this error.
Well a Native C++ pointer
Aniket Salunkhe wrote: IVideoWindow *pWidnow;
Is not going to be convertible to a managed object.
Aniket Salunkhe wrote: DirectShowLib::IVideoWindow ^
If you don't know that, then you need to do some studying of C++/CLI basics and fundamentals. There is a series of CLI beginner articles here on Code Project.
led mike
|
|
|
|
|
Aniket Salunkhe wrote: When I am calling SetPreview() from my VC++.Net 2008 MFC Application as follows,
IVideoWindow *pWidnow;//C++ DirectShow Library
CWinFormsControl<videowindow::videowindow xmlns:videowindow="#unknown"> *a1 = new CWinFormsControl<videowindow::videowindow>();
Handles to managed objects use ^, not * in C++.
Also you use gcnew, not new, to allocate them on the managed heap.
Aniket Salunkhe wrote: (*a1)->SetPreview(pWidnow);
Huh?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark, FYI, Aniket Salunkhe is trying to call managed code from native C++ according to this quote: "When I (Aniket Salunkhe) am calling SetPreview() from my VC++.Net 2008 MFC Application ...".
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
That was pretty obvious from the error message as well
I only commented about the syntax/language use.
I suppose I could have mentioned that (s)he'll have to
compile with /CLR.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: he'll have to
compile with /CLR.
I am already using this flag (/CLR).
|
|
|
|
|
I knew that from the error message.
You're using the wrong syntax for managed objects.
The error message is fairly clear.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The C++ DirectShow Library's IVideoWindow and C#'s DirectShowLib::IVideoWindow^ are not the same interface (at least externally). SetPreview is looking for C#'s IVideoWindow; thus, you may need to use COM callable wrapper (CCW) of your DirectShowLib::IVideoWindow^.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Wednesday, October 1, 2008 2:05 PM
|
|
|
|
|
George L. Jackson wrote: you may need to use COM callable wrapper (CCW) of your DirectShowLib::IVideoWindow^.
What is that?
|
|
|
|
|
I have a question regarding STA/MTA in .net
I need to build a COM object in .net whose threading model is required to be STA only (not Both,..) because it is not safe to be used in MTA apartment.
How to do it?
Thank you very much!
|
|
|
|
|
I have some code which use Debug::Print() to output some debug strings. I notice it also prints in the release build version. IIRC, this is not the case in C#.
Folks, any explanation for this anormaly?
Thank you very much!
Edited: I am using Visual Studio 2005. Looks like I got to use a #ifdef guard to prevent the Debug::Print from printing in the release build.
modified on Sunday, September 28, 2008 9:57 PM
|
|
|
|
|
Just for the record, the MSDN Library says (http://msdn.microsoft.com/en-us/library/system.diagnostics.debug.aspx[^]):
"ConditionalAttribute is not supported by the C++ compiler. To provide equivalent functionality, you must enclose calls to the methods of Debug in an #if defined(DEBUG) ... #endif block, and add the /DDEBUG option to the compiler command line or add #define DEBUG to the file."
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi,
I have one JNI shared libray which depends on a CPP library.
In my module loading CPP shared library first and loading JNI library, eventhough the dependant library is loaded JNI library tries to load CPP shared library.
Please let me know how to avoid loading an already loaded shared library ....
Thanks,
Yashu
|
|
|
|
|
Yashusid wrote: I have one JNI shared libray
As in Java Native Interface? If so this is not even close to being the correct forum. If not then what is it? Supply a link.
In terms of loading modules into Windows Processes put all the modules in a single location. The loader will see that it is already loaded and not load it again.
link[^]
Note Use extreme care when using this value. If LoadLibrary or LoadLibraryEx is called for the same DLL after the DLL is loaded, then the DLL references will not have been resolved. This is because the second call to LoadLibrary or LoadLibraryEx simply returns a handle to the already loaded DLL. In this case, the process is likely to terminate abnormally.
led mike
|
|
|
|
|
I have some code that fails when I do this:
Char mgData[] = new Char[numBytes];
Marshal::Copy(data, mgData, 0, numBytes);
...but does not fail when I do this:
Byte mgData[] = new Byte[numBytes];
Marshal::Copy(data, mgData, 0, numBytes);
data is of type char*, and contains binary data in the form of individual bytes (not represented as text at all). numBytes is the length of char*, when it was created with...
char* data = new char[numBytes]
The specific error that I'm getting is in Marshal::Copy, and the debugger points me to memcpy.asm. This leads me to believe that it's something unconventional, or that I'm simply not handling my unmanaged to managed conversions properly. There's a bit of background though... the reason why I'm trying to convert from unmanaged char* to managed Byte[] is because a BinaryWriter object won't properly write binary data when it's in the form of char*. If I were to call...
BinaryWriter.Write(char*) , it would simply write until it thinks that it's at the end of a text string (likely a null-terminated character, or something along those lines). Furthermore, I'm not sure if using the Byte instead of the Char is incorrect, since Byte is an unsigned type, and Char (I think) is signed, which matches char* (also signed).
Any suggestions?
|
|
|
|
|
FYI
System::Char is an Unicode character that corresponds to native C++'s wchar_t , and System::Byte corresponds to native C++'s char .
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I guess I was doing the right thing, then. I just thought there would be a signed/unsigned mismatch.
Thanks.
|
|
|
|
|
Cyrilix wrote: I just thought there would be a signed/unsigned mismatch.
Nah. Marshal.Copy() has no idea what your passed IntPtr points to.
You just have to make sure there's enough room there for whatever gets copied
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
(Sorry for my bad English in advance!)
I would like to know what do game developers think about C++/CLI and whether it's practical to use C++/CLI in game development. Or, is the performance that bad(like with C#) that native C++ is still dominating? If some game developers are around here, that would be cool!
|
|
|
|
|
I am not a game developer. IMHO, pure C++/CLI would have similar issues C# has. You can boost the performance of C++/CLI with native C++; however, it will never equal the performance of native C++ in many circumstances.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
HI I want an array to be filled with spaces when declaring it?
How would you do it?
array<wchar_t>^ indicators = gcnew array<wchar_t>(sentence->Length){L' '};
Is the the correct form?
Well but this only initializes the first element to space and the rest to null?
|
|
|
|