|
I wish to use BlowFish encryption for my project. How do I pass the value from the form textbox to the Blowfish Encrypt function?
The Blowfish algo is written in Classic C++, but the Form is in managed C++.
|
|
|
|
|
So your question has nothing to do with BlowFish. You want some one to tell you how to do mixed mode development, in an internet forum.
Typically that's not what these forums are for. Beginners are expected to use some instructional material ( University Courses, Books, Online tutorials, Online API References, Online Articles) to learn basics and fundamentals and then ask for assistance with specific problems in these forums. And in case you are thinking of posting another question, YES, there are a whole series of articles here on CodeProject that are introductory articles into CLI programming. Use searching or the menu system for the site in the left column but do it yourself rather than ask someone to provide you a link.
Your question is like: Teach me how to program?
led mike
|
|
|
|
|
|
Xaria wrote: wish to use BlowFish encryption for my project. How do I pass the value from the form textbox to the Blowfish Encrypt function?
The Blowfish algo is written in Classic C++, but the Form is in managed C++.
Why not just write a managed implementation of it. Can't be that hard.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I am trying to do just that.
Thanks
|
|
|
|
|
Hello,
I am trying to access the SHGetKnwonFolderPath function on Vista from NET and I get an exception:
My code looks the following:
[DllImport("shell32.dll")]
extern "C" int SHGetKnownFolderPath([MarshalAs(UnmanagedType::LPStruct)] Guid^ rfid, unsigned int dwFlags, IntPtr hToken, IntPtr ppszPath);
ref class KnownFolders
{
public:
static const Guid^ AddNewPrograms = gcnew Guid( "de61d971-5ebc-4f02-a3a9-6c82895e5c04" );
... snip ...
};
When running the following code the runtime raises an exception that parameter #1 can not be marshaled as there is no layout information available
String^ str;
IntPtr path;
if(Shell32::SHGetKnownFolderPath((Guid^)KnownFolders::AddNewPrograms, 0, IntPtr::Zero, path) == 0)
{
str = System::Runtime::InteropServices::Marshal::PtrToStringAuto(path);
System::Runtime::InteropServices::Marshal::FreeCoTaskMem(path);
}
(
|
|
|
|
|
As the exception message indicates, without structure layout, the Guid can't be marshaled.
Using the info in "How to: Convert Between System::Guid and _GUID[^]", you could marshal
the Guid as a byte array, something like:
[DllImport("shell32.dll", CallingConvention = CallingConvention::Cdecl)]
extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType::LPArray)] array<Byte> ^ar, UInt32 dwFlags, IntPtr hToken, [Runtime::InteropServices::Out] IntPtr %ppszPath);
...
String^ str;
IntPtr path;
array<Byte> ^ar = KnownFolders::AddNewPrograms->ToByteArray();
if(SHGetKnownFolderPath(ar, 0, IntPtr::Zero, path) == 0)
{
str = System::Runtime::InteropServices::Marshal::PtrToStringAuto(path);
System::Runtime::InteropServices::Marshal::FreeCoTaskMem(path);
}
Note I also changed the Path paramter so it would marshal as an Out parameter.
The "[Runtime::InteropServices::Out]" is optional - the "%" is NOT optional
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks, that does the trick!
|
|
|
|
|
Cool!
I forgot to mention - the "[MarshalAs(UnmanagedType::LPArray)]" is also
optional since that's the default marshaling behavior for the byte array handle.
I personally like seeing it there just so I know at a glance there's marshaling
going on for that parameter.
Also, the Environment::GetFolderPath Method[^] will get you common folder paths
without having to use interop.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Just wondering whether you have ever required to call a .Net Interface/DLL from c++ code?
I could load the library, but can’t get the function pointer!
Would you have any suggestions?
typedef int (*cfunc)(void);
cfunc CreateFunction;
HINSTANCE hLib=LoadLibrary(sFullName.c_str());
CreateFunction = (cfunc) GetProcAddress((HMODULE)hLib, "iSquare");
Thanks,
Debasis
|
|
|
|
|
Debasis10 wrote: call a .Net Interface/DLL from c++ code?
You can't from native c++ code. You can use C++/CLI, however, which is designed
to bridge the native/managed gap.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello to all,
I am having a .net application in which i am creating a thread which reads data from serial port.
I am having one buffer Buffer[1000] which store 1000 bytes data. Simultenously i have to display and store this data into one file. When buffer Size becomes 1000, i have to send message to main application form, to display this 1000 bytes data and also store it into a file.
I am having problem regarding how to send message to main application from a thread.I am facing this problem from last 10 days, but i am not geting proper solution.
Can anyone tell me please? It is urgent.
Thanks and Regards,
Abhijit
|
|
|
|
|
I would use pipes http://msdn.microsoft.com/en-us/library/aa365781(VS.85).aspx[^] but then again i am not up with the play on the latest .NET tools and tricks but "pipes" are tried n true easy solution to the messaging problem especially when u have to send data along with it.
otherwise if u dont need to send a chunk of data then u could simply use
PostMessage()/PostThreadMessage()
|
|
|
|
|
Hello!
You could use Invoke or BeginInvoke/EndInvoke to let
the main thread execute your delegate.
With Invoke, the worker thread waits until the handlers
have completed. There are examples in the msdn.
Alex
|
|
|
|
|
Can we reduce this function further in one simple statment as the compared number from -3 to +3 is same
|
|
|
|
|
I don't think so.
(you could use abs(x) > 3, but I don't think it would be faster)
|
|
|
|
|
Thanks for the reply but it is taking more CPU time than the given one.
|
|
|
|
|
if u are worried about CPU time taken for such a simple operation then i would check the ASM output that is generated from the code, i think u will find that a number of C code options will boil down to the same ASM in the end.
|
|
|
|
|
Hi. I'm using Visual Studio C++/CLI. I have a well developed class that now has a need to have a user interface for it. Normally I will determine if I need a form associated with a class when I create the class, so the class is created as a System::Windows::Forms::Form. But now I have a class that I did not think would need a form associated with it so it was defined as a simple C++ ref class. What is the proper way to add a form to the class? Should I create a new UI Forms based class and cut and paste everything in my existing class into it? Or is there a simple way to instantiate a new form as a method of the existing class?
Thanks,
Buck
|
|
|
|
|
BuckBrown wrote: Normally I will determine if I need a form associated with a class when I create the class, so the class is created as a System::Windows::Forms::Form. But now I have a class that I did not think would need a form associated with it so it was defined as a simple C++ ref class. What is the proper way to add a form to the class? Should I create a new UI Forms based class and cut and paste everything in my existing class into it? Or is there a simple way to instantiate a new form as a method of the existing class?
Buck, what's up dude? Ever heard of Object Oriented Design Principles, Best Practices, Separation of Concerns, Design Patterns, Model-View-Controller?
Any of this ringing any bells with you? You don't tightly couple a "class" with the presentation layer of your design, it's not considered Best Practice and there are Patterns like MVC that represent solutions for this.
led mike
|
|
|
|
|
Hi Mike,
Just so you know, I first learned programming using assembly on a state of the art Intel 8085 and our operating system was CP/M (that's what it was called before Microsoft bought it and renamed it MS-DOS). Over the years I have been forced to learn various programming languages on Data General, VAX, UNIX, and MS-DOS boxes, but all of the OO stuff was invented long after I got out of college. So the fact that I'm an over 50 microelectronics engineer with a EE degree and not a new Computer Science graduate, I can state with confidence that with the exception of Object Oriented Design Principles I've never heard of any of those terms before (nor whatever MVC means). You even mention a "presentation layer". I have never heard anyone use that term before. IO, User Interface, GUI sure, but "presentation layer"? I don't understand what you mean by "you don't tightly couple a class with the presentation layer". Visual Studio's forms designer seems to make things very tightly coupled. Anyways, if you could dumb down your responses for me that would be cool.
Thanks,
Old Buck
And my applications always work and do what they were designed to do.
|
|
|
|
|
|
Easy way would just be to make a new form class and make the class a member of the new form class. ugly? yes. best practise? no. will it do the trick? probably
|
|
|
|
|
How To create an array of form?
|
|
|
|
|
You create form array in the same way as you would create array of any other type.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|