|
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
|
|
|
|
|
|
I just jumped in to MC and am having some string problems.
I have 2 functions in c++ that I wanted to wrap with MC to use from c#. The def are as follows.
<br />
int EncryptString (wchar_t * pszString, wchar_t * & pszResultString);<br />
int DecryptString (wchar_t * pszString, wchar_t * & pszResultString);<br />
The first param of both is a string. the second is a string that acts as a buffer for the return value. How do I get these into MC?
I want to have a managed function that will take either 2 strings or a string and a StringBuilder.
<br />
void CAES::DecryptStr(String* DecString, StringBuilder* Buff)<br />
{<br />
<br />
}<br />
What do I need to put in the function to get DecString and Buff into something I can pass DecryptString? I need Buff to hold the output and return to c# intact etc.
TIA
|
|
|
|
|
Hello,
Check out System.Runtime.InteropServices.Marshal . Specifically: the StringTo... and PtrTo... methods.
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Thanks for the reply. I have been working with that for a while now. I got the simple wchar_t to go easily. Do you know how to do the string builder buffer? I need it to copy to the wchar_t and then get whatever comes out back into the string builder.
Also do you know of any good reading on this subject? I have found lots of stuff, just nothing more advanced than a simple string to string conversion.
Thanks!
This is what I have so far in the decrypt sub.
<br />
wchar_t __nogc* pStr = static_cast<wchar_t*>(Marshal::StringToHGlobalUni(EncString).ToPointer()); <br />
wchar_t __nogc* pBuf = ;
int Ret;<br />
<br />
Ret = DecryptString(pStr,pBuf);<br />
|
|
|
|
|
To copy the StringBuilder into the pBuf, you should be able to exactly the same thing that you did with the first String.
<br />
String* pStringTemp = Buf->ToString();<br />
wchar_t __nogc* pBuf = static_cast(Marshal::StringToHGlobalUni(pStringTemp).ToPointer());<br />
Then to copy back into the StringBuilder just do:
Buff->Remove(0,Buf->Length);
Buff->Append(new String(pszResultString));
Hope this helps get you going again... (not tested
-Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Thanks a lot!! That got me there.
Boy MC is giving me a headache.
|
|
|
|
|
Glad that I could be of help. I forgot to answer your question about reading material. I don't have any good articles off the top of my head, but a good book on the subject is:
Programming with Managed Extensions for Microsoft Visual C++ .NET--Version 2003[^]
Just the first chapter alone is worth the money. The author should give me a little cash, I think I have posted that book 3 times now here... oh well... I like it a lot...
I like MC++ but it is kind of a pain... It allows a lot of cool things to happen.
Yea, legacy code support
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
OK I'm about to throw MC out the window.
Here is my code
<br />
void CAES::EncryptStr(String* EncString, StringBuilder* Buff)<br />
{<br />
wchar_t __nogc* pStr = static_cast<wchar_t*>(Marshal::StringToHGlobalUni(EncString).ToPointer()); <br />
String* pStringTemp = "";<br />
wchar_t __nogc* pBuf = static_cast<wchar_t*>(Marshal::StringToHGlobalUni(pStringTemp).ToPointer());<br />
<br />
int Ret;<br />
<br />
Ret = EncryptString(pStr,pBuf);<br />
<br />
Buff->Remove(0,Buff->Length);
Buff->Append(new String(pBuf));
<br />
}<br />
This worked fine a few mins ago. NOTHING HAS CHANGED IN THE WHOLE PROJECT!!! Now I get an unhandled exception in mscorlib. It is a stack overflow exception. It happens on the Buff->Remove line. If I take it out it happens on the Buff->Append line.
The only think I did was make some functions in the non managed class I have private with the private: keywork in my header. After this it broke. I removed the private keyword and it's still broke.
Any ideas?
Further info: It happens when I call any framework thing after comming back from the dll also. I tried to show a messagebox and it failed also. This was after the call to EncryptString. I removed the Buff-> stuff so the method would return. It doesn, but I get the exception after it gets back now.
|
|
|
|