|
bsaksida wrote: Yes, but in stdafx.cpp.
not only ; in every cpp file of the project using stdafx.h as the precompiled header file
|
|
|
|
|
The file name just indicates where to stop pre-compiling - it doesn't HAVE to be called
stdafx.h 
|
|
|
|
|
Hi everyone,
I'm trying to use Jeff Atwood's Encryption class, but replicating a simple example yields lots of errors at compile time. Jeff's class is written in VB.NET, but AFAIK all .NET languages compile down to the same CIL, right? So I should be able to use it.
I've tried to rewrite the following VB.NET code in C++/CLI. Am I doing something wrong?
TIA,
Ralph
VB.NET:
<br />
Dim sym As New Encryption.Symmetric(Encryption.Symmetric.Provider.Rijndael)<br />
Dim key As New Encryption.Data("My Password")<br />
Dim encryptedData As Encryption.Data<br />
encryptedData = sym.Encrypt(New Encryption.Data("Secret Sauce"), key)<br />
Dim base64EncryptedString as String = encryptedData.ToBase64<br />
C++/CLI:
<br />
Encryption::Symmetric^ sym = gcnew Encryption::Symmetric(Encryption::Symmetric::Provider::Rijndael);<br />
Encryption::Data^ key = gcnew Encryption::Data("My Password");<br />
Encryption::Data^ encryptedData = sym->Encrypt(gcnew Encryption::Data("Secret Sauce"), key);<br />
System::String^ base64EncryptedString = encryptedData->ToBase64();<br />
|
|
|
|
|
Ralph A. Moritz wrote: I've tried to rewrite the following VB.NET code in C++/CLI. Am I doing something wrong?
Sounds like a nightmare to me.
Why not just use it out of a dll ? Or use something in the Cryptography namespace ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian Graus wrote: Why not just use it out of a dll ?
I've compiled Jeff's code into a DLL assembly, and I'm trying to use the encryption classes from the assembly. The problem is that when I try to create an Encryption::Symmetric object, the compiler says:
error C3673: 'EncryptionClassLibrary::Encryption::Symmetric' : class does not have a copy-constructor
Christian Graus wrote: Or use something in the Cryptography namespace ?
IMO Jeff's Encryption class is a lot simpler to use than the stuff in System::Security::Cryptography. But if I can't figure out how to get it working, I guess I'll have to use the latter.
Cheers,
Ralph
|
|
|
|
|
A copy constructor is one that takes an instance of the object, and copies the values into the class. So, just add one.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian Graus wrote: A copy constructor is one that takes an instance of the object, and copies the values into the class. So, just add one.
I know what a copy constructor is, but I have no idea how to create one in VB.NET or how to extend a VB.NET class in C++/CLI.
|
|
|
|
|
In VB.NET, a constructor is called new(), I think. I dunno I guess you should google it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
As far as I know, you cannot create copy constructors in VB.NET. It is possible a GC object may have been created on the stack (You have a missing "^" and "gcnew" somewhere!) when the code was converted from VB.NET.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I've given up on using Jeff's encryption library and decided to use the System::Security::Cryptography stuff instead. But just look at how much code is required to encrypt a string. Sheesh!
<br />
System::String^ EncryptString(System::String^ str) <br />
{<br />
System::IO::MemoryStream^ ms = gcnew System::IO::MemoryStream;<br />
SSC::RijndaelManaged^ rm = gcnew SSC::RijndaelManaged;<br />
SSC::CryptoStream^ cs = gcnew SSC::CryptoStream(ms, rm->CreateEncryptor(), SSC::CryptoStreamMode::Write);<br />
System::IO::StreamWriter^ sw = gcnew System::IO::StreamWriter(cs);<br />
sw->Write(str);<br />
<br />
sw->Close();<br />
cs->Close();<br />
ms->Close();<br />
<br />
array<System::Byte>^ buff = ms->ToArray();<br />
<br />
System::Text::UnicodeEncoding^ enc = gcnew System::Text::UnicodeEncoding;<br />
return enc->GetString(buff);<br />
}<br />
|
|
|
|
|
Ralph A. Moritz wrote:
array^ buff = ms->ToArray();
my code got mangled there. The above should read:
array<System::Byte>^ buff = ms->ToArray();
|
|
|
|
|
Sounds like you should write a wrapper class, or at least a wrapper method.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I don't have VB.NET installed (untick it out of habit) - but I looked at the VB code and it looks like the constructor's first argument is specified as By Val. Try de-referecing the handle and pass that - it may not work, but worth a try :-
Encryption::Symmetric^ sym = gcnew Encryption::Symmetric(*Encryption::Symmetric::Provider::Rijndael);
|
|
|
|
|
Sorry - scrap what I said. The argument is an enum.
|
|
|
|
|
How i converting value to string in c?
example:
int x=205;
char *str[10];
str=val(x); //i want str to be "205"
|
|
|
|
|
sprintf is the C way to do it. ostringstream is the c++ way. I did an article on ostringstream, here on Code Project.
You said C, and the code looks like C, so if it's not C++, google for sprintf, you should get a better understanding than I could give by just telling you how to do this one example.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
oops - just realised this is the C++/CLI forum. You are asking in the wrong place, try the Visual C++ forum ( my answer is still right, but for future reference... )
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
hi
im preety new to topic: "creating MEX-file with c++ files" so forgive me.
i've read some articles about creating MEX files in MATLAB by #C. i've also done some examples and it worked good.
but what about compiling a c++ code ?
my program is not funciton, called up with parameters. it's a simple one-way-working with no options code
when i try to compile it in matlab several errors occurs. i dont use mexFunction...
|
|
|
|
|
Do you mean C++/CLI, or are you in the wrong forum ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
hi, cam we make an exe appplication that works in a Dos mode using linux
and how it can be.
thank for your help
|
|
|
|
|
OK, you want it to run under linux. Well, this site is mostly about windows, this forum is entirely about C++/CLI ( that is, C++ with .NET ). Unless you're asking a Mono question, you're in the wrong forum.
But, a program that's written in C++ works in 'DOS mode' by default, if you mean in a console instead of with windows.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Visual C++ compiles windows exe. It doesn't work in pure DOS.
I suggest, you get a compiler, that compiles under pure dos. I suggest Turbo C++.
Visual c++ compilers will compile a dos box version, but it won't run in pure dos. Windows XP, and higher version, doesn't use dos. Windows 9x or lower still depending on dos.
In orther to use dos in linux, you have to get a linux version of dos emulator dosbox. In some distribution, it's included.
|
|
|
|
|
Hi all,
I have a situation where I need to return a fixed length string regardless of the length of a string that has been assigned to it. For example, if I wanted to have String1 which is made up of 12 spaces, then assing a returned value to a String2 which can be anything from 1 to 12 characters in length, how is this best done ?
The following may give you an idea where I'm coming from:
String^ Result; //This needs to be a fixed 12 characters.
String^ s1 = "ABC";<br />
<br />
Result = s1;
So I need Result to return 'ABC' + 9 spaces.
Hope this all makes some sense....
Fritzables.
|
|
|
|
|
String^ result;
String^ s1 = "ABC";
result = (s1->Length > 12 ? s1->Substring(0, 12) : s1)->PadRight(12);
Console::WriteLine("[{0}] Length={1}", result, result->Length);
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
George, you're a legend.... works a treat.
Thanks a million.
Regards
Pete <fritzables>
|
|
|
|