locked
Need Help: TypeLoadException was unhandled error RRS feed

  • Question

  • I got this error when debugging the program.
    I am testing out using DLL written in C in a Window Mobile Project.
    I start a Class Library and build a DLL file.
    Then add the DLL file as reference to the Window Mobile Project in C#.
    Everything is built but when the program try to call one of the function in the DLL i got the error.

    This is my first time program with C# and namespace and such.
    So I am pretty confused, is it because I define the DLL wrong, or did I did something I am not suppose to.
    Thanks a million.

    Following are the Codes:
    Class Library:
    #pragma once

    using namespace System;
    using namespace System::Runtime::InteropServices;

    #include "stdio.h"
    #include "string.h"


    namespace DLLClass {
      
        public ref class ClassECG {
            FILE* gstFileData;
            FILE* gstFileOutput;

            public:
            void stDLLConstructor (int iFileName)
            {   
                char sFileNameTemp[200] = "ECG\\";

                sprintf(sFileNameTemp, "ECG\\%ld.txt", iFileName);

                gstFileData = fopen("c:\\temp\\data.txt","r");
                gstFileOutput = fopen(sFileNameTemp, "w");
            }
        so on so for...
    }
    --------------------------------------------------------------------------

    This is how the function is called:

    private void menuItem3_Click(object sender, EventArgs e)
    {
                ClassECG stECG = new ClassECG();
                int iTemp = 10;
             
                stECG.stDLLConstructor(iTemp);
    }
    • Moved by Harry Zhu Friday, February 27, 2009 9:42 AM relating to Mobile development (Moved from Visual C# General to Windows Mobile Development)
    • Moved by Harry Zhu Friday, February 27, 2009 9:42 AM relating to Mobile development (Moved from Visual C# General to Windows Mobile Development)
    • Moved by Harry Zhu Friday, February 27, 2009 9:42 AM relating to Mobile development (Moved from Visual C# General to Windows Mobile Development)
    Tuesday, February 24, 2009 8:18 AM

Answers

  • Hi,

    Firstly you cannot use a DLL built for desktop directly in a Windows Mobile project. You need to create a Win32 DLL project under the "Smart Device" tab from the Visual Studio project templates, and select the Windows Mobile platform you are using (Windows Mobile 5 or 6 are most commonly used platforms currently). 

    Secondly,  C++/CLI is not supported on Windows Mobile. You need to write you DLL in native C/C++. To use the DLL in C#, you use a technique called P/Invoke.

    Regards,
    Chunsheng Tang
    Please mark the post that helps you, and unmark that does not. This benefits our community members.
    • Marked as answer by warrentang Monday, March 2, 2009 7:52 AM
    Monday, March 2, 2009 7:51 AM

All replies

  • do you have a type constructor?

    Tuesday, February 24, 2009 11:53 AM
  • No, i don't have the class constructor, ClassECG()
    I took the code directly from another test file so I didn't realize I need it.
    Tuesday, February 24, 2009 12:04 PM
  • It seems like any function i declare under the ClassECG will return the same error whether it does nothing or something.
    I try to write a function for for the constructor ClassECG(), but when it is called the same error occured.

    I tested the same DLL (With a few minor changes on the filepaths) with a C# Console program and the function perform perfectly. 
    So is it possible that Window Mobile Project can't work with DLL liberary?

    Please can someone confirm this.
    Thanks a million,
    Sincerely,
    Wednesday, February 25, 2009 4:30 AM
  • Hi,

    Firstly you cannot use a DLL built for desktop directly in a Windows Mobile project. You need to create a Win32 DLL project under the "Smart Device" tab from the Visual Studio project templates, and select the Windows Mobile platform you are using (Windows Mobile 5 or 6 are most commonly used platforms currently). 

    Secondly,  C++/CLI is not supported on Windows Mobile. You need to write you DLL in native C/C++. To use the DLL in C#, you use a technique called P/Invoke.

    Regards,
    Chunsheng Tang
    Please mark the post that helps you, and unmark that does not. This benefits our community members.
    • Marked as answer by warrentang Monday, March 2, 2009 7:52 AM
    Monday, March 2, 2009 7:51 AM
  • thank you this is very helpful.
    I will do that.

    Thanks a million,
    Sincerely.
    Monday, March 2, 2009 7:55 AM