|
First of all, I agree with the previous reply post. This is the C++/CLI (Managed C++) forum.
Secondly, when you are working with template classes, all your code need to be placed in the header file.
George
|
|
|
|
|
Thank you, and sorry for posting in the wrong forum. I found my answer - my textbook glossed over the fact that templates actually generate the classes/functions and therefore require all the code to be in the header file.
The C++ Lite FAQ did a great job of explaining the answer and possible solutions. Thanks again, and sorry.
http://www.atraeyu.org/
|
|
|
|
|
Hi All,
This works fine in debug mode, but in release mode I am getting errors thrown when passing std::wstring from managed to un-managed. I narrowed it down to one line...
std::wstring name2=L"test";
which in the debugger in debug build says {"test"}, but in release mode it says {"st"}.
To add to this, when I try and call my unmanaged function with...
m_node=new NW::Node(L"test");
it works fine in debug mode, but in release mode it blows up with unknown software exception.
If I change from Multithreaded DLL to Multithreaded debug dll in the c++ code generation options, it works. If I change back... it stops working again.
I thought it was maybe because I was passing std::wstring and that the implementation may somehow be different between the unmanaged library and the managed assembly, but I changed it to wchar_t and I still get the same problem.
I am very confused. Help!
Thanks
Rael
|
|
|
|
|
do you have UNICODE set in both DEBUG and RELEASE builds?
led mike
|
|
|
|
|
Yes, I checked that for all modules. I also checked to make sure they all have 'treat wchar_t as built in type' set to yes.
Another interesting thing. If I change from std::wstring to wchar_t* it still fails, but if I then turn off 'whole program optimization' then wchar_t* starts working, but std::wstring fails.
[Edit] Actually I tell a lie... it seems intermittent.
FYI, I have my unmanaged code compiled as a .lib using the /MD option, and my managed code is a DLL linking in the .lib also compiled with the /MD option.
Do you think this could be to do with the owner of the memory? Is it safe to pass pointers to memory allocated in managed code over to un-managed code?
Really scratching my head over this one.
Thanks
-- modified at 12:09 Monday 23rd October, 2006
|
|
|
|
|
Raeldor_ wrote: Is it safe to pass pointers to memory allocated in managed code over to un-managed code?
Memory should be marshalled from native to managed and managed to native. But your post does not indicate that is happening.
led mike
|
|
|
|
|
I am doing the following where in_name is System::String and name is std::wstring, and the node parameter is wchar_t* (used to be std::wstring, but that didn't work either)...
MNW::MarshalString(in_name, name);
m_node=new NW::Node(name.c_str());
Where NW::Node is my unmanaged class. MarshalString is...
void MarshalString(System::String^ s, std::wstring& os)
{
const wchar_t* chars =
(const wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer();
os = chars;
Marshal::FreeHGlobal(IntPtr((void*)chars));
}
Do I need to do more than this?
[EDIT]
having said that, even this...
pin_ptr<const wchar_t> str=L"test";
m_node=new NW::Node(str);
Blows an error. UNLESS I compile with the debug DLL. :S
-- modified at 12:47 Monday 23rd October, 2006
|
|
|
|
|
Not sure this will help but I would try:
IntPtr iPtr = Marshal::StringToHGlobalUni(s);
const wchar_t* chars = (const wchar_t*)iPtr.ToPointer();
os = chars;
Marshal::FreeHGlobal(iPtr);
MODIFIED: Keep in mind I am really confused since your initial post makes no mention of managed memory and does not seem to match at all what you have put in your last post.
led mike
|
|
|
|
|
Ugh, please excuse me... I am a moron. I copy+pasted the additional library directories from the debug to the release version, so it's picking up the debug versions of the libraries.
Just out of interest, would you tend to pass strings as parameters by std::wstring or wchar_t*? Is there a performance hit either way?
Thanks for your patience!
|
|
|
|
|
Raeldor_ wrote: would you tend to pass strings as parameters by std::wstring or wchar_t*?
Well for an "output" parameter wchar_t* is not going to work. For input parameter you could overload:
void MarshalString(std::wstring& is)
{
MarshalString( is.c_str());
}
void MarshalString(wchar_t* pis)
{
}
NOTE: std::wstring& is a "reference" which does not have any performance penalties compared with wchar_t*.... however std::wstring will copy the string data onto the stack.
void MarshalString(std::wstring& is)
is not equal to
void MarshalString(std::wstring is)
led mike
|
|
|
|
|
I always initialize variables by habit from C/C++ programming.
So in managed C++ I'll do this:
Int32 MyInt32 = 0;
I was told this is redundant. Is that true? And if so I would sure like to know where
in the documentation it states that value type are initialized to 0 - for peace of mind.
Until I see it I'll live with redundancy
Mark
|
|
|
|
|
Mark Salsbery wrote: I was told this is redundant.
While technically it is true that is not a reason to discontinue a "good practice" IMHO.
led mike
|
|
|
|
|
Thanks led mike.
Do you happen to know where it's documented? I can't find it anywhere!
Mark
|
|
|
|
|
Probably arises from this: Do not initialize unnecessarily[^]
However, it also explicitly states: "This rule ignores Managed C++ assemblies."
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
How can I get the DNS IP address that the local client is using?
Like to find a way using c++ and not MFC
thanX
|
|
|
|
|
Hi,
I am trying to wrap my C++ objects in a managed wrapper. I have...
public ref class MCamera
{
private:
NW::Camera* m_camera;
public:
MCamera(MNW::Vector3 in_source, MNW::Vector3 in_target, float in_near, float in_far, int in_outputWidth, int in_outputHeight);
~MCamera();
IntPtr GetCameraPtr();
};
and I'm putting a breakpoint on the code for the destructor but it never gets called. I've enabled unmanaged debugging and other breakpoints work, but it seems this never gets called. Does anyone know why the destructor is not getting called, even when the application is closed?
Thanks!
|
|
|
|
|
|
I HAVE TO write a programm that can erease all data from hard drive
that no one can recover it again.There are planty of algorithms that can do
that and I wanna use them in my programm.I have to write it for my exam pro
ject at university. Any help?? PLIZ...sorry for my English couse i`m not Pol
ish.
|
|
|
|
|
zetkonrad wrote: I HAVE TO write a programm that can erease all data from hard drive
that no one can recover it again.
And it needs to be in managed C++ ?
zetkonrad wrote: There are planty of algorithms that can do that and I wanna use them in my programm
OK, if you know the algorithms, why not use them ?
zetkonrad wrote: I have to write it for my exam project at university
OK, good luck doing your project. If you get stuck while working on it ( as oppossed to before you do any work ), by all means, ask specific questions in the correct forum, and we would love to help you.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi there,
I need to build an optimized circular buffer of variabe length messages in C++. The elements are std::string types and I can dedicate a fixed amount of space to this log, in the sense that I can preallocate a memory block of fixed size and work in there. Can anybody indicate me some examples or techniques in C++ (in fact it should run under Linux) to do this ?
Thanks for your help
Marco
marcof
|
|
|
|
|
this is a managed C++ forum, try the Visual C++ forum.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi all,
I am beginner in C++.Just want to know whether we can use only c++ to preodeuce a program.
|
|
|
|
|
You can use any language you like, there are hundreds.
Darka [ Xanya]
"I am not a slave to a god that doesn't exist."
|
|
|
|
|
This is the managed C++ forum. I think you wanted the Visual C++ forum.
You can write a program using only C++ if you want to. But, as someone said, you can use lots of other languages, too. Realistically, the languages most used on a PC are C, C++, C#, VB6 and VB.NET.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Could anyone please, answer this question for me
Is it necessary to create a constructor when you are dealing with things like mathematical formulae that involves using classes?
Thanks for your prompt response.
Regards,
SKG!
skg
|
|
|
|