Encrypt.exe

Posts 16–30 of 48 · Page 2 of 4
Quote Originally Posted by Hell_Demon View Post
easiest way to get a GUI working would be to use MSVC++ 2003 .net since that has a working visual resource editor and can basicly give you the full code for creating a window and add buttons and stuff to it.
I tried that. Never again .

Using vc++ to create a gui involves dealing with microsoft's managed c++. It was a pain, to put it lightly and G-Rated. I'm probably going to go with QT and/or wxWidgets from now on.

You're kidding me right?
Making a basic windows app with Managed C++, C#, VB.NET is so easy it's hardly worth being called programming.... Drag & drop a few controls, set some properties & event handlers and call it good..

I've been through C, C++, Managed C++ and C# in my job and using the .Net stuff is THE EASIEST of anything to make a windows app..

Also - you don't HAVE to use Managed C++, you can still use MFC, or plain old Win32 code if you're really into self-punishment
Quote Originally Posted by B1ackAnge1 View Post

You're kidding me right?
Making a basic windows app with Managed C++, C#, VB.NET is so easy it's hardly worth being called programming.... Drag & drop a few controls, set some properties & event handlers and call it good..

I've been through C, C++, Managed C++ and C# in my job and using the .Net stuff is THE EASIEST of anything to make a windows app..

Also - you don't HAVE to use Managed C++, you can still use MFC, or plain old Win32 code if you're really into self-punishment
Yeh zeco into what's that word called... damit can't remember it... starts with a m ...
Microsoft winapi programming GUI
Masochism?
Mortification?

Quote Originally Posted by B1ackAnge1 View Post
Masochism?
Masochism thats it ! Pain turns him on o_O?
Quote Originally Posted by why06 View Post
Masochism thats it ! Pain turns him on o_O?
>_> You are saying strange things about me >_>.
xD Eitherway the problem with managed C++ was that you had to use their custom string class. Ok fine that's not too bad. But then there was no suitable way to convert from a standard string.

And i couldn't just use the managed string because it is immutable and one other reason that i can't remember.

....Wait a minute.

Oh nvm. Ok.
Quote Originally Posted by zeco View Post
>_> You are saying strange things about me >_>.
xD Eitherway the problem with managed C++ was that you had to use their custom string class. Ok fine that's not too bad. But then there was no suitable way to convert from a standard string.

And i couldn't just use the managed string because it is immutable and one other reason that i can't remember.

....Wait a minute.

Oh nvm. Ok.

char* still works in Managed c++
and you can convert it just fine: System::Runtime::InteropServices::Marshal::PtrToSt ringAnsi((IntPtr)(void*)pChar);
or
LPCTSTR str = static_cast<LPCTSTR>(Marshal::StringToHGlobalAnsi( gcString).ToPointer());
...
Marshal::FreeHGlobal(const_cast<LPTSTR>(str)); //since you're dealing with 'non-managed' resources here you need to free the memory yourself.


though natively the .net strings are unicode which could create some other issues.

I mix native C++ strings & .NET strings all day long
Quote Originally Posted by B1ackAnge1 View Post
char* still works in Managed c++
and you can convert it just fine: System::Runtime::InteropServices::Marshal::PtrToSt ringAnsi((IntPtr)(void*)pChar);
or
LPCTSTR str = static_cast<LPCTSTR>(Marshal::StringToHGlobalAnsi( gcString).ToPointer());
...
Marshal::FreeHGlobal(const_cast<LPTSTR>(str)); //since you're dealing with 'non-managed' resources here you need to free the memory yourself.


though natively the .net strings are unicode which could create some other issues.

I mix native C++ strings & .NET strings all day long
See that's what I'm talking about. I have no experience with Windows API and you just used so many scope resolutions I have no idea what class your calling D: . Could you please dumb it down a little. Make it something like "How to cast managed strings for: DUMMIES". Then I could understand what your doing. I'm not used to using predefined classes yet in C++.
Ok Line by Line:

LPCTSTR str = static_cast<LPCTSTR>(Marshal::StringToHGlobalAnsi( gcString).ToPointer());

LPCTSTR str = a 'long pointer const string' (there is a madness to the naming convention ) but it's basically the same as 'const char*'

so we're defining a old fashioned char pointer called 'str' which is getting assigned with 'something'.

Then jumping to the back:
Marshal::StringToHGlobalAnsi(gcString).ToPointer() ;

The Marshal Class (which is in the System.Runtime.InteropServices namespace so you can either type all that crap out everytime or have a using statement on the top of your code which tells the compiler you're using that namespace so you don't have to label each and every little thing) is a static class ,so no need to create an instance of it, which exists basically purely to help dealing with 'non-managed' (.net) objects/memory etc.

The signature of StringToHGlobalAnsi in .NET is:
IntPtr StringToHGlobalAnsi(string s);
Which takes a .NET string ('gcstring' in above sample) and returns an IntPtr (Let's assume 32 bit Pointer on 32 bit system) to the memory address of where the converted string will be located in memory.

We're trying to cast this IntPtr we have to a LPCTSTR which we can't do until we actually take the IntPtr and cast it to what in C++ would be a void* pointer (anything in C++ can basically be cast to a void pointer). This is done by calling .ToPointer() on the IntPtr. Then we call a static_cast since we know this will work (so no runtime checking of the type like a dynamic_cast).
If you don't know about static vs dynamic cast, do some reading - you can do some great stuff with that.

Ok so Now str has your string.. and you can do whatever the heck you want with it..
When you're done with it it though you need to clean it up: Since we created a new string object in a .NET Environment (Managed C++ /C# etc) that's not garbage collected we need to get rid of it ourselves when we're done which is simply a call to FreeHGlobal

Marshal::FreeHGlobal(const_cast<LPTSTR>(str)); //since you're dealing with 'non-managed' resources here you need to free the memory yourself.



The other way around - reading a 'c++' style string into a .NET unicode string uses the first sample and the reverse logic; we cast a Char* to a void* and then to an IntPtr so that the Marshal class knows how to use it:

string s = Marshal.PtrToStringAnsi((IntPtr)(void*)pChar);


What may get confusing is that for instance in C# everything is '.'
Namespace.NameSpace.StaticClass.Method
and calling properties/methods it's all SomeObject.DoSomething(this.X); etc

While in Managed C++ you'll run into Double Colon's for Namespace & static classes
Namespace::NameSpace::Class::StaticMethod
but in your code you can still have object.DoSomething() (if you allocated on the stack) and object->DoSomething(); (if you allocated on the heap with 'new')

Good times
I don't get this line:
Code:
iput[i] = iput[i] ^ key;
And why is there a encrypt function when decrypt takes care of both?

And whats the difference between endl and '\n'?

When/how are the files actually being encrypted?
Quote Originally Posted by Ayn View Post
I don't get this line:
Code:
iput[i] = iput[i] ^ key;
it is XORing the referenced character in the string iput and then placing that XORed char back into the string.


And why is there a encrypt function when decrypt takes care of both?
Mainly to make it nice and user friendly. Doesn't really make it that easy however for other coders to understand xD. I imagine using some kind of shared function would be a better approach that's what zeco did in his updated model he is working on.

And whats the difference between endl and '\n'?
none. you'll find that there's about a 100 different ways to do something in any programming language.

When/how are the files actually being encrypted?
it is a XOR bit encryption: This should give you a quick description of what XOR bit encryption is: XOR Encryption
iput[i] = iput[i] ^ key;

So that is basically saying "The 'i' element of the iput string array = it self XORed to the char key"?

Is the "^" an operator?

Also, I don't know why your code doesn't want to compile on visual c++ 2008 express edition.. (works with bloodshed tought).

Also does: "iput[i] = iput[i] ^ key;" encrypt when used on a decrypted file and decrypt when used on a encrypted file?
Quote Originally Posted by Ayn View Post
Is the "^" an operator?
That it is the XOR operator

Also, I don't know why your code doesn't want to compile on visual c++ 2008 express edition.. (works with bloodshed tought).
And that's probably because you can only compile source in a project in VC++. Just make a new project.

Oh. And yes to all ur other questions too.
Yay! See this time your really long post actually came in handy. Haha...

EDIT: Just got through reading the whole thing and I have to say it makes a lot of sense now. Sometime I just get a little intimidated when you throw a huge line of code like that, but now I actually undestand what your talking about. Thanks a lot BA

Oh and BTW:
Quote Originally Posted by B1ackAnge1
What may get confusing is that for instance in C# everything is '.'
Namespace.NameSpace.StaticClass.Method
and calling properties/methods it's all SomeObject.DoSomething(this.X); etc

While in Managed C++ you'll run into Double Colon's for Namespace & static classes
Namespace::NameSpace::Class::StaticMethod
but in your code you can still have object.DoSomething() (if you allocated on the stack) and object->DoSomething(); (if you allocated on the heap with 'new')
I'm actually more familiar with the C# calling conventions, it is very similar to Java, which is my first language
I actually find the C++ notation more confusing. Especially this one right here "->". But that's just me I guess.
Posts 16–30 of 48 · Page 2 of 4
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us