class library
-
hi.. I hve design .net based C++ class library. I want to use it in vb.net proj. My class library code compile without an error. But when i access that library in vb.net proj it gives me an error (its run time error) error discription: Unhandled Exception: System.BadImageFormatException: Could not load file or asse mbly 'Appa, Version=1.0.2598.12775, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect fo rmat. File name: 'Appa, Version=1.0.2598.12775, Culture=neutral, PublicKeyToken=null' at Anna.MyModule.Main() WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\M icrosoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure lo gging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus ion!EnableLog]. =========================================================== // Appa.h #pragma once using namespace System; namespace Appa { public ref class MyClass { public: int Add(int x, int y); }; } =========================================================== // This is the main DLL file. #include "stdafx.h" #include "Appa.h" namespace Appa { int MyClass :: Add(int x, int y) { int k = x+y; return k; } } ================================================= //MyModule.vb Module MyModule Sub Main() Dim obj As New Appa.MyClass Console.WriteLine(obj.Add(10, 15)) End Sub End Module ================================================= plz help me guys
-
hi.. I hve design .net based C++ class library. I want to use it in vb.net proj. My class library code compile without an error. But when i access that library in vb.net proj it gives me an error (its run time error) error discription: Unhandled Exception: System.BadImageFormatException: Could not load file or asse mbly 'Appa, Version=1.0.2598.12775, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect fo rmat. File name: 'Appa, Version=1.0.2598.12775, Culture=neutral, PublicKeyToken=null' at Anna.MyModule.Main() WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\M icrosoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure lo gging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus ion!EnableLog]. =========================================================== // Appa.h #pragma once using namespace System; namespace Appa { public ref class MyClass { public: int Add(int x, int y); }; } =========================================================== // This is the main DLL file. #include "stdafx.h" #include "Appa.h" namespace Appa { int MyClass :: Add(int x, int y) { int k = x+y; return k; } } ================================================= //MyModule.vb Module MyModule Sub Main() Dim obj As New Appa.MyClass Console.WriteLine(obj.Add(10, 15)) End Sub End Module ================================================= plz help me guys
You'd be better off asking this in the C++ forum. My C++ is pretty rusty, but this doesn't look like a COM componet you've written, or a .NET assembly. You're trying to use a C++ style class in managed code, and that just isn't going to work. It needs to be rewritten using CLI (Managed C++) in order to be used the way your doing it now. But, like I said, you're in the wrong forum for an accurate answer to this question.
Dave Kreskowiak Microsoft MVP - Visual Basic