0
Answer

MissingMethodException

thomaass

thomaass

19y
1.8k
1
Hi, I am trying to call an unmanaged funcrtion from a simple eMbedded Visual C++ dll, but I only get the MissingMethodException. This is the first time I'm trying do use unmanaged code. Here is a sample of my code: c++ dll: header file: #ifdef TTWRAPPER_EXPORTS #define TTWRAPPER_API __declspec(dllexport) #else #define TTWRAPPER_API __declspec(dllimport) #endif // This class is exported from the ttwrapper.dll class TTWRAPPER_API CTtwrapper { public: CTtwrapper(void); // TODO: add your methods here. }; extern TTWRAPPER_API int nTtwrapper; #ifdef __cplusplus extern "C" { #endif TTWRAPPER_API int fnTtwrapper(); #ifdef __cplusplus } // extern "C" #endif cpp file: #include "stdafx.h" #include "ttwrapper.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } TTWRAPPER_API int nTtwrapper=0; TTWRAPPER_API int fnTtwrapper() { int t = 15; return t; } CTtwrapper::CTtwrapper() { return; } my simple C# device app: using System.Runtime.InteropServices; using System; using System.Drawing; using System.Collections; using System.Windows.Forms; using System.Data; namespace Managed { public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.MainMenu mainMenu1; [DllImport("ttwrapper.dll", EntryPoint="fnTtwrapper")] public static extern int fnTtwrapper(); public Form1() { InitializeComponent(); } static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { try { int i = fnTtwrapper(); this.textBox1.Text = "taller er: " + i; } catch(Exception ex) { this.textBox2.Text = ex.Message; } } } } Read that many ask for DUMPBIN exports, this is: Section contains the following exports for ttwrapper.dll 00000000 characteristics 42819B5C time date stamp Wed May 11 07:42:52 2005 0.00 version 1 ordinal base 4 number of functions 4 number of names ordinal hint RVA name 1 0 00001030 ??0CTtwrapper@@QAA@XZ 2 1 00001000 ??4CTtwrapper@@QAAAAV0@ABV0@@Z 3 2 00003028 ?nTtwrapper@@3HA 4 3 00001028 fnTtwrapper Summary 1000 .data 1000 .pdata 1000 .rdata 1000 .reloc 1000 .text Anyone who can help me?? I'm testing on a real device via visual studio .net 03 Thomas