|
Using DLL Export you can export your C/C++ variables and functions to make them available. However, you can not just export an entire class and use it in C#.
The direct problem here is that you are accessing a member function (Test) without an instance of your test-class being created.
Probably the best way to interface in a class based manner between C++ and C# is to use COM; that is, create a COM class in C++, export it, and then use the COM class in C#.
|
|
|
|
|
Hi all,
I have been trying to write encrypt and decrypt functions whose signatures require the input and the output strings to be in 'void*' type only. The code works fine if the inputs can be specified as IBuffer^ but in the other case the source string and the encrypted->decrypted string do not match. I've googled a lot but to no good. Please help...it's urgent.
IBuffer^ byteArrayToIBufferPtr(byte *source, int size)
{
Platform::ArrayReference<uint8> blobArray(source, size);
IBuffer ^buffer = CryptographicBuffer::CreateFromByteArray(blobArray);
return buffer;
}
byte* IBufferPtrToByteArray(IBuffer ^buffer)
{
Array<unsigned char,1U> ^platArray = ref new Array<unsigned char,1U>(256);
CryptographicBuffer::CopyToByteArray(buffer,&platArray);
byte *dest = platArray->Data;
return dest;
}
int DataEncryption::encryptData(EncryptionAlgorithm algo, int keySize, void* srcData, const unsigned int srcSize,
void*& encData, unsigned int& encSize)
{
LOG_D(TAG, "encryptData()");
if(srcData == nullptr)
{
LOG_E(TAG,"");
return DataEncryption::RESULT_EMPTY_DATA_ERROR;
}
if(srcSize == 0)
{
LOG_E(TAG,"");
return DataEncryption::RESULT_SIZE_ZERO_ERROR;
}
IBuffer^ encrypted;
IBuffer^ buffer;
IBuffer^ iv = nullptr;
String^ algName;
bool cbc = false;
switch (algo)
{
case DataEncryption::ENC_DEFAULT:
algName = "AES_CBC";
cbc = true;
break;
default:
break;
}
SymmetricKeyAlgorithmProvider^ Algorithm = SymmetricKeyAlgorithmProvider::OpenAlgorithm(algName);
IBuffer^ keymaterial = CryptographicBuffer::GenerateRandom((keySize + 7) / 8);
CryptographicKey^ key;
try
{
key = Algorithm->CreateSymmetricKey(keymaterial);
}
catch(InvalidArgumentException^ e)
{
LOG_E(TAG,"encryptData(): Could not create key.");
return DataEncryption::RESULT_ERROR;
}
if (cbc)
iv = CryptographicBuffer::GenerateRandom(Algorithm->BlockLength);
IBuffer ^srcDataBuffer = byteArrayToIBufferPtr(static_cast<byte*>(srcData),256);
encrypted = CryptographicEngine::Encrypt(key, srcDataBuffer, iv);
byte *bb = IBufferPtrToByteArray(encrypted);
encData = IBufferPtrToByteArray(encrypted);
encSize = encrypted->Length;
return DataEncryption::RESULT_SUCCESS;
}
int DataEncryption::decryptData(EncryptionAlgorithm algo, int keySize, void* encData, const unsigned int encSize,
void*& decData, unsigned int& decSize)
{
LOG_D(TAG, "decryptData()");
if(encData == nullptr)
{
LOG_E(TAG,"");
return DataEncryption::RESULT_EMPTY_DATA_ERROR;
}
if(encSize == 0)
{
LOG_E(TAG,"");
return DataEncryption::RESULT_SIZE_ZERO_ERROR;
}
IBuffer^ encrypted;
IBuffer^ decrypted;
IBuffer^ iv = nullptr;
String^ algName;
bool cbc = false;
switch (algo)
{
case DataEncryption::ENC_DEFAULT:
algName = "AES_CBC";
cbc = true;
break;
default:
break;
}
SymmetricKeyAlgorithmProvider^ Algorithm = SymmetricKeyAlgorithmProvider::OpenAlgorithm(algName);
IBuffer^ keymaterial = CryptographicBuffer::GenerateRandom((keySize + 7) / 8);
CryptographicKey^ key;
try
{
key = Algorithm->CreateSymmetricKey(keymaterial);
}
catch(InvalidArgumentException^ e)
{
LOG_E(TAG,"encryptData(): Could not create key.");
return DataEncryption::RESULT_ERROR;
}
if (cbc)
iv = CryptographicBuffer::GenerateRandom(Algorithm->BlockLength);
byte *cc = static_cast<byte*>(encData);
IBuffer ^encDataBuffer = byteArrayToIBufferPtr(cc,256);
decrypted = CryptographicEngine::Decrypt(key, encDataBuffer, iv);
byte *bb = IBufferPtrToByteArray(decrypted);
decData = IBufferPtrToByteArray(decrypted);
decSize = decrypted->Length;
return DataEncryption::RESULT_SUCCESS;
}
|
|
|
|
|
You need to provide more information about the problem, what does not work, and which lines of code are giving the problem.
Use the best guess
|
|
|
|
|
Hi Richards,
Thanks for your response. I found the problem. First let me describe the issue: Suppose my source string(say 'pData') is "SampleTextSample" and I encrypt it using encryptData() which stores the encrypted string in 'encryptedData'(suppose). Then I call decryptData() with 'encryptedData' as the input and in turn decryptData() stores the decrypted string in 'decryptedData'(suppose). Now logically, pData and decryptedData should be equal. But this is not happenning in my code.
Error: Using CryptographicBuffer::GenerateRandom() for creating key and initialazation vector in both encryptData() and decryptData(). Thus I am using a different key and initialization vector in encryptData() and another key and initialization vector in decryptData(). Hence the results don't match.
Solution: Arranged to use the same key in both encryptData() and decryptData().
|
|
|
|
|
yourchandrashekhar@gmail.com wrote: and another key and initialization vector in decryptData(). Why would you expect it to work with different keys?
Use the best guess
|
|
|
|
|
I have VisualC++ Ver 5. I know it's old but I have been using it for close to 20 years.
My problem is that when running in debug mode on WinXP VC++ crashes often.
When running on Win2K it runs for hours without problems.
Is there something I should know avout running VC++ on a WinXP computer.
Bob Macklin
Seattle, Wa
|
|
|
|
|
Try to run in Windows 2000 compatibility mode. First thing that comes to mind
|
|
|
|
|
I am using Visual Studio 2008 on a Windows 7 machine to generate a utility to validate TMATS and Chapter 10 file. These are standardized files used in telemetry systems. The files begin with a text based description of the data (7 bit ASCII) followed by large amounts of telemetry data in binary format. The binary data will not be shown, but there are some validation checks to be done.
In the text based preamble there are about ten different major sections, some rather long. Each section describes some aspect of the data. The basic format is an identifier that ends with a colon, followed by text that ends with a semicolon. The next identifier follows.
My plan is a separate dialog or window for each. The user will be able to edit the data and write out to a new file.
I am unsure as to the best solution type. So far I am leaning towards an MFC application with single document support. (Only one file will be open for reading only, and a new file optionally opened for writing.) The next best option seems to be with Dialog support. Or maybe someone will suggest something else completely.
This will be open source code posted on my web site for others in the telemetry industry to use and comment on. I plan to make all the classes and code as simple as I can so it can be ported to other systems. But I will not go to extreme lengths for portability.
I am fairly good at writing code, but on the lower end of intermediate for Visual Studio.
Pleas make your suggestions.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
bkelly13 wrote: classes and code as simple as I can so it can be ported to other systems
hmm, I think that rules out MFC ..
Seriously .. I would first abstract out what you need to do with a file, to get your sections etc - this might be one class or dll ..then I'd look at the UI - why dont you grab a copy of balsamiq for example and mock up possible UI's - or even resort to plain pencil and paper sketches
Once you've got the abstraction/logical stuff on paper, then worry about what you're going to build it in
'g'
|
|
|
|
|
Hello Garth,
Yes, I have a pretty darn good idea of how I want the data displayed. I have done a lot of thinking on this project. If you think the desire for portability rules out MFC, then what does it rule in?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
well, depends on 'how much portability' - I thought of 'Qt' and C#/Mono first off .. if you go the C#/Mono route I think that gives you winforms on linux (Mono)
'g'
|
|
|
|
|
I have visual studio and home and at work, but neither of the suggestions you made. What would you recommend within VS?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
|
VS for Visual Studio
We have only Windows where I work. I do not expect the code to simply compile and run on other operating systems. I just want to ease the task a bit for someone that might want to do that.
So which Visual Studio Template do you suggest for this project?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
nooo .. you dont say
I think if you stick with a pure VS/Microsoft environment, your portability options are limited, again, depending on 'what portability' you want .. what I was thinking of with the Mono stuff is, and I'd need to check, it allows you to have pretty well one code-base - you'd just have to compile it for mono on the Linux platform
Why not write it in VS/MFC now, the core functionality (ie, not the display stuff) can be separated out into its own layer, and then consider where else/what else (if ??)you need it to run on...
There are 'Open IDE's for c, c++ iirc, that work with VS compiler, GCC etc (although the name of one eludes me right at this second)
|
|
|
|
|
Re: nooo ... you dont say.
Re: Re: not sure about the 'within vs'
That sounded to me like you did not know what I intended with "vs." I did not mean to be sarcastic or anything.
Within MFC: I read about the various options: multi document, single document, and dialog in the help file, but it was really not very informative. Single document and multi document both provide a window with File open menus and the such already added. Dialog does not have that, but it "appears to be" a much simpler project. I only need to have one document open at a time.
Keeping this simple: There are about ten sections to a TMATS header. To make it simple for the reader I want to put the data for each major section in a separate dialog/window/(or some silly entity).
So which MFC option would you take?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
I would probably go Dialog, or Single document,
thought 1 : a tab bar, each tab being a section/TMATS header
thought 2 : 2 'panes' - left hand 'pane' is a tree structure (or listbox ?) of the file sections, when clicked upon, the TMATS header is displayed in detail on the right hand 'pane'
|
|
|
|
|
This is really helpful for me. I would not have thought of either one. If I google each will I find a good description?
I think the multiple tabs would be easier, but the split pane concept (kind of like Windows Explorer?) would also be cool. What is the approximate work effort for each? Maybe on a one to ten scale? I don't really care what the ten on that scale really means, just a comparison between the two. Maybe assign ten to the more difficult one and assign something less than ten to the easier one.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
just on a quick thought, the tabs are easier - caveat : as long as you only use them for 'displaying' data, ie, you dont have things going on in tabs that you need to pass between/to other tabs (Ive used a 5 tab bar as a workflow type thing, but an error in tab 3 meant they had to go back to tab 2 for example). One thing that may go against this is the size of the dialog, vs the number of tabs - 'fitting them on/scrolling them' so all the info is apparent to the user - with the dual pane view, you might not have that issue.
Im thinking '4' for tabs, and maybe '7' for split-pane
Again, if you have a class, with unit tests etc, that can handle parsing, 'getting sections', getting data from your TMATS files, then fitting it with a new UI shouldnt be a biggie
Im pretty sure google would bring up plenty of articles .. there's bound to be some lurking here on cp, if only for ideas
|
|
|
|
|
Thinking of Tabs: If I have a class in charge of writing, can it access the tabs to fetch the data, then write the data to a new file?
I presume I would need to create some type of writer class that would be able to poll each tab asking for the data contained within the tab. (Presuming each tab is a separate object ) to provide the data to the file writer. Then the file writer class would poll each tab to get the data to write out.
Its past my bedtime so I'll not respond again and catch up tomorrow. But again, this has been very helpful for me. Thank you for taking the time to maintain this conversation.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
I forgot about this [requirement]
>> The user will be able to edit the data and write out to a new file.
So maybe the tabs have some sort of edit - possibly hex edit control on them
Its not impossible - a 'commit changes' or 'write to file' button on the main dialog would loop through the tabs writing the data obtained from the edit control on it.
I think I would write, from an abstraction point of view ...
3. GUI Code
2. Tab Manager - Possibly linked to buffer manager/dirty flag - you need to know the order of the tabs and if they have been changed or not
1. File Parser/Writer
its about bed time for me too
|
|
|
|
|
Hi all!
I want to do it, same as my topic...
do pratical???
if this can, and can u help me.
thanks so much
|
|
|
|
|
Hi guys,
I'm confused. I need to create interprocess communications between x64 and x86 processes running on the same machine.
Can I use COM for it? Cannot see anything on web.
Or does that mean that I must use DCOM?
Thanks for help.
|
|
|
|
|
Both COM and DCOM are dangerous to use and can easily crash both processes if there is a bug.
IMHO it is better when you use sockets for the inter-process communications because it makes the way your communication works more reliable and the two processes gain a bit of independence (of course you have to add error handling for failed communication attempts, otherwise you are having the same problem as with DCOM and COM).
Just my two cents about how we use to do it at our company.
|
|
|
|
|
I will take into account your 2 cents . Still, the question is open.
|
|
|
|
|