locked
MFC dll in c# web Application RRS feed

  • Question

  • User-537745843 posted

    I have a MFC dll which is used for scanning a document from scanner and i want to use that dll in web application for scan and uploading a document.I am not familier with MFC .Is it possible to refer th MFC dll?

    I tried referring the dll but when i run it im getting error "External Component throws an exception".i would be very thankful if any1 could help me on this.

     

    Saturday, August 6, 2011 10:15 AM

Answers

  • User197322208 posted

    Depends if the dll have a COM interface or exports a function.

    If it is a COM, just reference that.

    If not, you should use DLLIMport for the function of the dll. See http://msdn.microsoft.com/en-us/library/aa288468%28v=vs.71%29.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 6, 2011 4:40 PM
  • User-537745843 posted

    I got the solution.

    The call to MFC dll sholud like this:

      [DllImport(_dllLocation, CallingConvention = CallingConvention.Cdecl)]
            [return: MarshalAs(UnmanagedType.LPStr)]
            public  static extern   string getpath([MarshalAs(UnmanagedType.LPStr)]  string name);
    Thanks for the help.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 11, 2011 1:34 AM

All replies

  • User197322208 posted

    Depends if the dll have a COM interface or exports a function.

    If it is a COM, just reference that.

    If not, you should use DLLIMport for the function of the dll. See http://msdn.microsoft.com/en-us/library/aa288468%28v=vs.71%29.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 6, 2011 4:40 PM
  • User-537745843 posted

    I am using the dll to call a function.Now the error im getting is

    A call to PInvoke function 'App_Code.tvheafo_!Scancsharp+UnsafeNativeMethods::getpath' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

    this is the code used for calling the function

     string cs = Scancsharp.UnsafeNativeMethods.getpath(file);

    this is the code im using to define the function in dll

      [DllImport(_dllLocation)]
            [return: MarshalAs(UnmanagedType.LPStr)]
            public static extern string getpath([MarshalAs(UnmanagedType.LPStr)]  string name);

     this is function definition in dll

    extern "C" __declspec(dllexport) LPTSTR getpath(LPSTR aFilePath)
    	{
    coding...
    }
    What wrong am i doing? 
    Sunday, August 7, 2011 3:03 AM
  • User-537745843 posted

    I got the solution.

    The call to MFC dll sholud like this:

      [DllImport(_dllLocation, CallingConvention = CallingConvention.Cdecl)]
            [return: MarshalAs(UnmanagedType.LPStr)]
            public  static extern   string getpath([MarshalAs(UnmanagedType.LPStr)]  string name);
    Thanks for the help.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 11, 2011 1:34 AM