|
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
|
|
|
|
|
|
I have some C code for sending data though the parallel port, but the thing is that it uses things that are exclusinve to linux such as "peek" in it, and it wont complie in wideows...
any idea of how I could complie this on XP?
/\ |_ E X E GG
|
|
|
|
|
It will not compile and run on NT 4.0 or better (Win2K, XP, Win2003 ...) because a user application is not allowed to access the hardware directly. You must write or use a device driver for this. I think if you search this site you will find one. If my memory is correct P.J. Naughter wrote one.
John
|
|
|
|
|
I'm just starting to dive into Visual Studio .NET 2003 and have been attempting to find the answer on how I can use C++ managed DLL's with an older VC6.0 MFC application. Here's the scenario:
I have several large MFC applications that currently use functions contained in MFC DLL's. These DLL's aren't large so converting the DLL's to a true managed DLL in .NET is not cumbersome however, attempting to convert the applications at this stage would not be feasible. The converted DLL's will also be used by new .NET managed applications.
My question is simply can a managed DLL written in C++ (or C# for that matter) under .NET be used by traditional VC6.0 MFC applications as well as new .NET web form applications? If so how does one setup the DLL to do this?
- stub
|
|
|
|
|
stub wrote:
If so how does one setup the DLL to do this?
Yes, you can get VC6 to work with Managed DLLs, but you will need to look into the topic of COM Interop . This makes it so that a Managed DLL acts just like a COM Dll and therefore can be used by any COM compatible language (VC6, VB6, etc).
-Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
There is another way besides COM interop, but it's not easy and probably not recommended (being that most of the functions and structures are undocumented).
You can host the CLR yourself using the unmanaged functions of the .NET Framework. You create a default AppDomain that creates your application's AppDomain. From there, you can actually do some things with the managed DLL, but it is a difficult process. COM interop is definitely easier, I just wanted to provide another alternative.
For more information, look-up CorBindToCurrentRuntime and CorBindToRuntimeEx . This will give you the starting points for the rest.
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|