WindowsCE, CF + Rijndael encrypt., I'm stuck




Answer this question

WindowsCE, CF + Rijndael encrypt., I'm stuck

  • Nidonocu




  • L West

    VS 2005 supports both NETCF V1 and V2.

    Since CE is Unicode it's a good idea to get rid of char and use WCHAR instead all the time. This way you could simply pass string (or StringBuilder to pass string from native to managed). If you do need to pass char, conversion from Unicode would be needed on managed side or native side.

    Please take a look at these P/Invoke samples:

    http://msdn.microsoft.com/netframework/programming/netcf/netcfsamples/default.aspx pull=/library/en-us/dnnetcomp/html/pinvokelib.asp

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnnetcomp/html/netcfadvinterop.asp

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnnetcomp/html/netcfintrointerp.asp



  • arganis

    Getting strings back is a bit more complicated:

    extern "C" NATIVETEST_API void TestString(WCHAR * s, int size)
    {
    wcscpy_s (s, size, L"Hello World"); // Copy string to the managed buffer, make sure it's big enough.

    // s = L"Hello World"; // Don't - will crash with AV.

    }

    [DllImport("NativeTest")]
    private extern static void TestString(StringBuilder s, int size);

    StringBuilder sb = new StringBuilder(256); // Max string size is 256

    TestString(sb, sb.Capacity);

    Console.WriteLine ("Got string '{0}'", sb.ToString());

    I would suggest only return integers (e.g. error code) and use pointers to pass everything else.



  • Mark Goldstein

    I believe I need the platform SDK that was built from their OS image... I tried to download the SDK for the 9090 series and it said eVC was required to install! I think that has to be wrong, surely I should be able to install the SDK anyway and use it inside VS2005 when I create native Win32 lib.

    I should be able to go to new project -> win32 smart device application/dll and select their platform once the sdk is installed correct

    edit:  I created an app in mfc and it executed just fine.. but the dll fails to work.. is there something different about libraries here



  • Mike_in_NC

    P/Invoke is quite limited on NETCF V1, you can't return float/double and you can't pass doubles as arguments. You can use a pointer to float/double though:

    [DllImport("CEWin32Test.dll")]
    private static extern void Multiply(float a, float b, out float c);

    extern "C" void WIN32DLL_API Multiply(float a, float b, float * c)
    {
    *c = a*b;
    }

    Also, next time please state exact problem you're having (e.g. exception) and NETCF version you're using. You wrote pretty big message twice and yet omitted essential information. Something like this might do better:

    “I'm getting NotSupportedException on attempt to pass float from P/Invoke on NETCF V1 (managed/native declaration below), how to workaround ”



  • Dmitry Shaporenkov

    THANK YOU.

    I cannot tell you how much I appreciate the help. Finally got a string returned back using that example you gave me. Sorry if I seemed angry/fustrated. Now I can finally get to what I need to do to make this all work.

    Ilya Tumanov you're the best.

  • gdubya

    Please do not cross post. Merging...



  • Zzermont

    I tried using StringBuilder instead of string, application threw a "Native exception error" everytime I was using StringBuilder

  • SavitaHK

    Still receiving fatal application errors, if I wasn't marshaling my string correctly is this the type of error that I would expect

    Why does float return a NotSupportedException with CF2.0 I tried using System.Single as the MSDN says, no difference.

  • Nanja Raje Urs

    I think I got it working, my problem was returning a float.

    I have been able to return an int and a bool just fine. returning the float, and then in .NET using float or Single both failed..

    Why This works on my desktop What's wrong with my function declaration in C++ or C#

  • sandeep437



    Ilya,

    I have contacted Symbol received a regfix for their SDK install, and have their sdk installed.  It is no different than the problems I had before.

    I wrote another test app/dll..

    extern "C" NATIVETEST_API bool TestBool()
    {
    return true;
    }

    extern "C" NATIVETEST_API int TestInt()
    {
    return 42;
    }

    extern "C" NATIVETEST_API long TestLong()
    {
    return 8;
    }

    extern "C" NATIVETEST_API float TestFloat()
    {
    return 42.3;
    }

    extern "C" NATIVETEST_API char* TestString()
    {
    return "Hello World";
    }

    extern "C" NATIVETEST_API const char* TestString2()
    {
    return "Hello World";
    }

    [DllImport("NativeTest")]
    private extern static bool TestBool();

    [DllImport("NativeTest")]
    private extern static int TestInt();

    [DllImport("NativeTest")]
    private extern static int TestLong();

    [DllImport("NativeTest")]
    private extern static float TestFloat();

    [DllImport("NativeTest")]
    private extern static String TestString();

    [DllImport("NativeTest")]
    private extern static String TestString2();

    float function throws a "NotSupportedException"

    TestString() gives me this:

    Fatal application error
    "Application WinCETest.exe has performed an illegal operation and will be shut down. If the problem persists, contact the program vendor.

    Program: WinCETest.exe
    Exception: 0xC0000005
    Address: 01926B54

    and TestString2() -- which I didn't think is right at all gave me..

    An unexpected error has occured in WinCETest.exe.
    Details: OutOfMemoryException

    I'd admit I'm not that great at writing native code or I'm rusty.. Am I doing something stupid

    .NET CF v2.0 is the only framework installed on my device.

    Symbol MC9090-G
    VS2005
    .NET CF v2.0

    If you see this and are unsure can you post to let me know that you at least saw it, since it has been marked answered. Just I'm extremely fustrated on this, and it would put me at ease more. By the way, I have had no problem making all those test functions work on the full framework.


    edit: I just saw your post, tried WCHAR* and no luck, now checking out the examples.. will post again with any new efforts / good news

  • akjoshi

    Ilya,

    Thanks for the response.

    I thought I mentioned somewhere I was writing code in VS2005, so I should be using CF v2.0 not 1. Sorry if I left out any information, I usually try to include everything.

    I need to pass char* to string and back, but I have no success still.

    Is it possible that I can post an example project that someone can look at

    I still haven't gotten an SDK from Symbol.. could it be possible that the WindowsCE SDK ARMV4I that I'm using is working intermittently with my device half the time I'm struggling to make the int function work again, it's starting to seem random, and I've had no hope of returning any type of string, although I was able to pass a String to a function that expected a char* I was unable to return char* as a String. Let me do some tests, and post what exceptions I get.

  • rwbogosian


    extern "C" NATIVETEST_API WCHAR* TestString()
    {
    return L"Hello World";
    }

    and in C# a return type of String.. with fatal app error. I have tried anything and everything I can think of, still nothing.. and i've been staring at this one problem for a few days.

  • Richard Warlow

    Here's my problem..

    I have a Symbol MC9090-G - http://www.symbol.com/product.php productID=855

    I'm currently writing an application for it in the CF.

    Where I work we use some Rijndael C++ code to do our encryption with our user file. I need to use this same file that we use everywhere else. (I'm aware there's a .NET rijndael class but the only thing I need to supply our code with is a key, and .NET class wants numerous, numerous other items that this code doesn't seem to be comparable with)

    Here's a quick example of some of the code. From our Rijndael.cpp (multiply this by a few thousand lines of code)

    for(i=0; i<BC; i++)
    {
    *pi = ((unsigned char)*(in++) << 24);
    *pi |= ((unsigned char)*(in++) << 16);
    *pi |= ((unsigned char)*(in++) << 8);
    (*(pi++) |= (unsigned char)*(in++)) ^= m_Kd[0][ i ];
    }


    Obviously I cannot rewrite this, but I need to use this code with pointers and standard C++ function calls (memset/memcpy) in my application!

    I figure I need to wrap this in a DLL. Because of the heavy use of pointers and the memset/memcpy function I thought I would need a native win32 library or mfc I don't care which, is this the correct idea or.. is it possible to copy all of this into a .NET library

    I know how to create Win32 / MFC libraries for use in the .NET framework on a desktop but I do not know how to create a native library for use on a WindowsCE 5.0 device. I tried downloading the Windows CE 5.0 SDK. Then created a new project and selected Win32 smart device project, and platform as "STRANDARDSDK_500". (note: the chipset on Symbol's link says it is a Intel PXA270 if it matters) Then I copied the code I used in the Win32 library for a simple function to import into .NET (which I knew worked) Here's the code. (WIN32DLL_API is defined as __declspec(dllexport/dllimport))

    extern "C" float WIN32DLL_API Multiply(float a, float b)
    {
    return a*b;
    }

    I tried compiling this dll under numerous options for platform type under windowsCE. ARMV4I, x86, SH4. All the options it gave me in the WindowsCE 5.0 SDK.

    I wrote a simple app that has 1 button 1 label... and I import my library like so. And when the button is clicked label1.Text = WinceRijndael.Mult(5, 6).ToString();

    public class WinceRijndael
    {
    [DllImport("CEWin32Test.dll")]
    private static extern float Multiply(float a, float b);

    public static float Mult(float a, float b)
    {
    return Multiply(a, b);
    }
    }

    I used activesync's explorer to copy my app's .exe and the other project's dll to the same "Test" folder in program files. Every time the dll fails to be invoked.

    Please help me I'm very lost. I have no idea how to get this crazy encyption code into a library I can use on my device so I can use it in the CF similar to the normal framework. I found that my process is of the ARM type or something, but I do not know if I need to take this into consideration or not.

    This has been on my mind for more than a few weeks, if you can tell me how to create any standard c++ dll that I can use in my app and I can get it imported to the CF I should be fine, other than memset/memcpy and heavy use of pointers the code doesn't use much else.

    addition : I was able to use the ARMV4I platform type to create a blank mfc application that did execute on my scanner, but when I try to load the dll it did not work.

    Any example of any simple function in a native C++ library that has been imported into a .NET app that runs on my scanner would help. I cannot believe that this can be that difficult.


  • WindowsCE, CF + Rijndael encrypt., I'm stuck