Hello helios,
I created a Win32 C++ Project, but enabled /clr for namespace usage
That gives me access to (supposedly) the same .NET namespaces I would get from VB
So far, I have the following which does compile, but I have not gotten far enought to test anything yet (although having it compile is a really big deal for me at this point):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <string>
#include <stdlib.h>
using namespace std;
using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Security::Cryptography;
_declspec(dllexport) string Encrypt(string strText, string strEncrKey)
{
// Initialize a Byte array with 8 bytes for Initial Vector of the Encryptor
Byte IV[]= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
//Convert std:string to System:String for the GetBytes() Function
String^ s = gcnew String(strEncrKey.c_str());
//Get the UTF8 Encoding for the System:String
array<Byte>^ byKey = Encoding::UTF8->GetBytes(s);
return "0";
}
|
I am slowly working my way through it...the C2664 Error was basically telling me that the GetBytes() function couldn't convert std::string (because it uses System::String)
1 2 3 4 5 6 7 8 9 10 11 12 13
|
>Main.cpp(20): error C2664: 'cli::array<Type> ^System::Text::Encoding::GetBytes(cli::array<wchar_t,dimension> ^)'
: cannot convert parameter 1 from 'std::string' to 'cli::array<Type,dimension> ^'
1> with
1> [
1> Type=unsigned char,
1> dimension=1
1> ]
1> and
1> [
1> Type=wchar_t,
1> dimension=1
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
|
The 3395 Error apparantly is saying (in my own simple terms) that I cannot use a System::String parameter with a '^' for an exported function in a /clr enabled project althought I'm not deep enough to understand it all. I did work around it for now.
1 2 3 4 5 6 7 8 9 10
|
_declspec(dllexport) string Encrypt(String^ strText, String^ strEncrKey)
Raises the Error:
Main.cpp(12): error C3395: 'Encrypt' : __declspec(dllexport) cannot be applied to a function with the
__clrcall calling convention
and
_declspec(dllexport) string Encrypt(String strText, String strEncrKey)
Raises the Error:
Main.cpp(11): error C3149: 'System::String' : cannot use this type here without a top-level '^'
|
So I settled on using a std::string parameter and converting it to System::String for the GetBytes() function.
To answer your last question...using the express version of VB.NET, you are very limited in creating a COM DLL. I could do it, but it becomes a huge hassel. It's a little better with the Ultimate version (it adds all the code you need, strong names the assembly, etc...), but ultimately (no pun intended) it still sucks. VB.NET is not built for COM. Therefore, I figured, "what the hell. I can program in 4 or 5 different languages, and I usually pick up on a new language within hours of just playing with it. I think I'll just hurry and get this done in C++ and be done with it!" LOL.
Well, now it's personal. I haven't figured out all the pointers and header files and deep crap yet, but I am determined to learn it now.