Okay OriginalGriff, RSVP
I have written a C# front-end program, in which calls a bunch of DLL "C" functions(API's). and the communications between the two parts has been great.
But recently, I was working on the program and must have done something wrong, and now I can't call a DLL function period.
So now, every time I try to run the this program, I get the following errors:
* Exception thrown: 'System.BadImageFormatException' in textlib.exe
* An attempt was made to load a program with an incorrect format.
(Exception from HRESULT: 0x8007000B)
It seems like when I attempt to call a DLL function(API) from within the C# program, the following error/exception(s) (above) surfaces.
I sure could use some help OriginalGriff
What have you tried? is is in the screen below. Again Thanks.
What I have tried:
Okay OriginalGriff, RSVP
SOME NEEDED EXAMPLES, PLEASE;
Here in my C# program,(below)are some examples of "C#"'s import DLL function call declarations,
referencing an external DLL file to be used, with referenced API calls.
*** In the C# sharp environment:
[DllImport("textlibrary.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int MM_MAXNUMBEROFTEXTFORMATS(ref int numfmts);
[DllImport("textlibrary.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int MM_ISVDATE(StringBuilder bufferdate);
[DllImport("textlibrary.dll", CallingConvention = CallingConvention.Cdecl)] public static extern
int MM_APPSTESTSRUN(StringBuilder testrundate, int ifmtid, int idpassval, ref int iostat);
DllImport("kernel32.dll")] static extern uint GetSystemDirectory(
[Out] StringBuilder lpBuffer, uint uSize);
[DllImport("Advapi32.dll")] public static extern bool GetUserName
(StringBuilder lpBuffer, ref int nSize);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern uint
GetWindowModuleFileName(IntPtr hwnd, StringBuilder lpszFileName, uint cchFileNameMax);
*** In the "C" DLL environment:
#include <time.h>
#pragma once //// I'm using implicit linking, .lib file - linker file input.
#ifdef TEXTLIBRARY_EXPORTS
#define TEXTLIBRARY_API __declspec(dllexport)
#else
#define TEXTLIBRARY __declspec(dllimport)
#endif
extern "C" { TEXTLIBRARY_API int MM_JDECYYDDDxOperation(int pdopcode, char* passdjdedate8,
char* rtnhumandate, int* iostatx);
TEXTLIBRARY_API int MM_AXDYs(char* testitem, int addnumdays, int* irtnerrval);
TEXTLIBRARY_API int MM_TheISONotationforms(char* xpdtheccyyform11, int imee, int* iostatzs1);
TEXTLIBRARY_API int MM_ListOutAllUserNames(char* wfilename260, int* filesw, int* ierrsw) ;
}
*----------------*
Now for the question(s), please...
I have a program that consists of two parts(a C# program(the front end) and a DLL File [with a
bunch of DLL function(APIs)) calls] that worked quite well together for quite a while, but
has since recently stopped and no more communications were achieved. I cannot figure out
why/how/what it has stopped and to understand why. It seems like I may have done
something, but I don't remember doing it and why. I've noticed some of the forms that have
worked before stopped, have a few errors.
So now, every time I try to run the this program, I get the following errors:
* Exception thrown: 'System.BadImageFormatException' in textlib.exe
* An attempt was made to load a program with an incorrect format.
(Exception from HRESULT: 0x8007000B)
It seems like when I attempt to call a DLL function(API) from within the C# program, the
following error/exception(s) (above) surfaces.
So how can I get these two entities to communicate with each other again? Successfully?
I've checked out most of your Site's error-questions and solutions relating to this problem,
and it seems like my programs are in sync and are following the same rules as given in the
solutions provided. The C# program and the dll file, each compiles successfully, and the
IDE knows where the DLL file is located and shows it. It seems like the C# program would
run ok by itself, without calling any of the DLL functions(APIs).
I can use these "C" dll file function(APIs) calls in other "C" programs and they work ok.
But I need these " 'C' dll file function(APIs) calls" to be used in my C# program also.
Could someone or ones help me out, in finding what is going on and what I did wrong and then
achieve successful communication between these two parts. Cause right now, I'm at a
stand-still. How can I "link" a DLL to a C-sharp program or am I doing it right?
But anyrate, Thanks for any help.