troubleshooting Question

Return array of bytes (byte[]) from the unmanaged code

Avatar of Yurich
YurichFlag for New Zealand asked on
C#
4 Comments1 Solution635 ViewsLast Modified:
Hello,
I need some help with getting my unmanaged DLL to work.

that's my library function signature (in DLL):

extern "C" __declspec( dllexport ) BYTE* encrypt( char* ch_input, char* ch_key )
{
}


that's how I declare it in C#:
[ DllImport( "cbr_conv.dll" )]
static extern byte[] encrypt( string input, string key );

//... throws an exception
byte[] output = encrypt( input_string, key );

That doesn't work and I have "can not marshal return value" this error. I have very vague understanding of marshalling, but I know there're some restrictions on returning data from unmanaged code. Would appreciate if someone helps me to get it working. I have access to both files (C++ DLL and C# client) so I can change anything.

Thanks,
Yurich


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros