|
const has nothing to do with __pin. The former simply means that you won't change the value. The latter is used so that the CLR will not move the data in memory.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Simpler way is to use ATLMFC.
<br />
#include <atlstr.h>
<br />
String* strSomething;<br />
CString str = strSomething;
But you will need to find a way to pack your ATLMFC7.0 redistributable when you release your app.
Hope this helps.
|
|
|
|
|
How do you debug managed code that used unmanaged code? I have several managed functions that call functions that are unmanaged. If I use #pragma unmanaged on the unmanaged functions to get compiled code out of them, I can't step into them from the managed code. I have the debug properties of the project set to Mixed. Auto doesn't work either. What other settings am I missing?
TIA
|
|
|
|
|
|
I checked them to be sure and they are off for debug compile. I really haven't changed the settings much. I started a managed C++ dll project and change a few things like /noentry on, precompiled headers off, changed additional dependencies to be (odbc32.lib odbccp32.lib Netapi32.lib msvcrt.lib)
Thanks
PS also if I remove all the pragma's to make the entire thing managed code it works fine.
PSS I create a simple console .net app, added an unmanaged function and it works fine. The only difference between the 2 is one is a dll the other is an exe. I compared the setting of my dll to the console app and made sure they matched. A couple were off, but even when I changed them I still can't step in to the managed code in my dll.
|
|
|
|
|
Yeah, I am having the same outcome. I have functions with embedded asm and when I try to jump into those functions, I can't. I just jump over them. It seems that if the compiler deems that the function must be compiled as x86 code directly (ie not MSIL and then jitted) you can't jump into them
-Nathan
P.S. 100th post... I need to post more or something; I am behind a lot of others with the same CP age as me.
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
jspano wrote:
PS also if I remove all the pragma's to make the entire thing managed code it works fine.
I havent really tried with pragma's, I ussually setup the compiler on a per file basis. You can email the project /solution and I can check.
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
OK Now I have the StackOverflow problem that I thought I had solved. Nathan, it's the one we talked about before, leppie it's about 10 posts down.
I have the following code.
<br />
void CAES::EncryptStr(String* EncString, StringBuilder* Buff)<br />
{<br />
wchar_t __nogc* pStr = (wchar_t*)(Marshal::StringToHGlobalUni(EncString)).ToPointer(); <br />
<br />
int sz;<br />
sz = ((wcslen(pStr) / 15) + 1) * 64;
wchar_t (*pBuff) = new wchar_t[sz];<br />
int Ret;<br />
<br />
<br />
Ret = EncryptString(pStr,pBuff);<br />
<br />
Buff->Remove(0,Buff->Length);
if(Ret != -1)<br />
{<br />
Buff->Append(new String(pBuff));
}<br />
<br />
delete [] pBuff;<br />
Marshal::FreeHGlobal((int)pStr);<br />
}<br />
I have a vb.net project that I put a call to this function in. I pass it a String set to "Hello" and a empty stringbuilder.
On this line: wchar_t (*pBuff) = new wchar_t[sz];
I get the error:An unhandled exception of type 'System.StackOverflowException' occurred in jjutility.dll
on this line. I got this error before, and modified the code to what is above. The error went away. Now it's back. I can't think of anything else I have changed.
It might not be a MC problem though. I am pretty rusty at C++. haven't used it in a while.
I also found that the problem is with the code
int sz;<br />
sz = ((wcslen(pStr) / 15) + 1) * 64;
wchar_t (*pBuff) = new wchar_t[sz];
and doesn't matter what comes before it.
the line wchar_t (*pBuff) = new wchar_t[sz]; errors no matter what I use for sz, be it the sz variable or a hardcoded number.
Have I been staring at this too long and missed something simple??
|
|
|
|
|
How do you do it by a per file basis?
Another way I thought of is to just put the pragma's in if not debug statements. This would turn them on in release compile.
Any ideas if this is good or not?
TIA
|
|
|
|
|
Right click properties , on the file in question. You can also do multiple selections and set properties for them.
One thing I did notice is that specifying /NOENTRY , the compiler tries to convert all code to IL. But I could be wrong...
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
Thanks for the info. I'll give that a try. I think I have all the problems fixed except for the managed to nonmanaged debuging.
Edit - Never mind I had to take the /clr off the main project file and do it per file that way.
Edit2 - Still can't step into the unmanaged code.
|
|
|
|
|
Thanks, I did that and now I get
fatal error C1190: managed targeted code requires '#using <mscorlib.dll>' and '/clr' option
I did include mscorlib.dll.
To test I started a brand new .net console app and added a cpp file that I set to compile non managed. the only code in it is
#include "stdafx.h"
I get the same compile error.
Edit - Ok fixed it. Removed the /clr option. That fixed it.
|
|
|
|
|
I've been able to resolve most of this. I started out with a fresh project from scratch. The Stackoverflow ended up going away when I removed the /noentry option. I know it's supposed to be there, but it works without it for now.
|
|
|
|
|
What was your final conclusion about debugging mixed code?
From what I can tell, you cannot jump into directly compiled C++ code. Only if the compiler sees that it can compile the C++ code to MSIL can you then jump into it from MC++.
NOTE: About the StackOverFlow problem, did you ever try putting a __nogc in front of the pointer?
wchar_t __nogc* chrs = new wchar_t[sz];
-Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
I think the overflow was from lack of knowledge. From some ideas I got from leppie it has gone away. I removed the noentry option and the /clr option from the main project. I then did the /clr option individually for managed files and turned it off for nonmanaged files. It works much better now. I know I hade the __nogc* on my pointer to the managed string I sent in as a param. I don't think I had it on my pointer to a wchar_t block. I'll add that also as another precaution.
For debuging I am still up in the air. I haven't gotten it to work in a real project when you mix managed and unmanaged. I have gotten it to work with a quick test project. I still might be wrong in the test project though.
I created a .net console app. In the cpp file it gives you, I added a function called MyFunct() and put a pragma unmanaged before it. Then in the main function I called it. It stepped into it fine. Granted this isn't a dll like my other project and it is very simple. If I have time today, I will experiment some on it.
|
|
|
|
|
I'm writing data to the network and I'm having trouble doing a task that would be very simple in unmanaged C++: write an Int32 to the stream. The NetworkStream class takes a byte array as a parameter in Write(). I'm not sure how to efficiently convert an Int32 to a byte array. Sure, I could use division a squeeze out a byte at a time, but that's hardly efficient. Any ideas on how to copy the 4 bytes that are an integer into an unsigned char __gc []?
Thanks in advance,
Tim
|
|
|
|
|
Take a look at BitConverter.GetBytes().
|
|
|
|
|
I knew there had to be an easy way to do it, but I couldn't find it. Thanks!
|
|
|
|
|
|
Scuse the typos -- B::Lookup should of course return B *; and insert indentations as appropriate.
READIN writin rhythmetic
|
|
|
|
|
Okay, I see now that the problem with solution B is that instances of B can be moved on the managed heap after the __pin pointer is out of scope. So never mind that idea... Any comments on the first, more messy solution? Any ideas for tidying it up?
READIN writin rhythmetic
|
|
|
|
|
When using the Managed C++ compiler, will the compiler generate any of the missing 'Rule of Three' methods if they are missing? ie, if I don't provide a default ctor, dtor, copy ctor or an op=, what of these will get generated by the Managed compiler?
|
|
|
|
|
|
ur help will be bless by the lord ..amen
how to implement a class date ?(class,inheritance,control structures) included above method inside.
a method to ensure user entered 1st date return true(or 1) before the second date to return false(or 0)
another method Christmas which given a date, should return the number of days until the next Christmas day(december25).
another method ..given two dates, return the no. of days between the given two dates. The program should cope with dates having different months.
|
|
|
|
|
How do I make a simple C solution in VS.NET??? just a C console application...
/\ |_ E X E GG
|
|
|
|