EDN Admin
Well-known member
<span style="font-family:Tahoma,Helvetica; font-size:small Im building and running a program called EditorApp, which is a C# program from the Game Coding Complete, 3rd Edition, textbook, but am getting a problem when it dynamically loads Editor.dll,
a file that I build from a C++ project. Here are the details:<br/>
<br/>
1) The error occurs in EngineDisplayForm.cs, line 138, which is where it calls NativeMethods.EditorMain. Here is the entire line of code inside that file:<br/>
<br/>
NativeMethods.EditorMain(hInstance, IntPtr.Zero, hwnd, 1, this.DisplayPanel.Width, this.DisplayPanel.Height);<br/>
<br/>
The code referenced in NativeMethods is:<br/>
<br/>
const string editorDllName = "Editor.dll";<br/>
[DllImport(editorDllName)]<br/>
public unsafe static extern int EditorMain(IntPtr instancePtrAddress, IntPtr hPrevInstancePtrAddress, IntPtr hWndPtrAddress, int nCmdShow, int screenWidth, int screenHeight);<br/>
<br/>
<br/>
2) The Editor.dll file is in the same directory as my EditorApp.exe, I build it there, and it is definitely found by the program. In fact, by executing this one line of code, Editor.dll is Loaded and then Unloaded 3 times. The output (note Ive abbreviated
the full path) from running this one line of code is:<br/>
<br/>
EditorApp.exe: Loaded ...EditorAppEditor.dll, Symbols loaded.<br/>
EditorApp.exe: Unloaded ...EditorAppEditor.dll<br/>
EditorApp.exe: Loaded ...EditorAppEditor.dll, Symbols loaded.<br/>
EditorApp.exe: Unloaded ...EditorAppEditor.dll<br/>
EditorApp.exe: Loaded ...EditorAppEditor.dll, Symbols loaded.<br/>
EditorApp.exe: Unloaded ...EditorAppEditor.dll<br/>
<br/>
<br/>
3) After these 3 Loads/Unloads, it produces the following exception:<br/>
<br/>
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)<br/>
<br/>
<br/>
4) Note that I have just done a full build of Editor.dll with the latest versions of all code<br/>
<br/>
<br/>
5) For my Editor project, I have specified during linking for it to have No Fixed Base Address (/FIXED:NO). When not specified I know it can present this type of problem for C# programs to link to C++ .dlls<br/>
<br/>
<br/>
6) Heres the full C# build with path abbreviations. Perhaps of particular note is "EditorApp.exe: Loaded ImageAtBase0x73d30000, Loading disabled by Include/Exclude setting." When I start the app, pause at a breakpoint, and open the Modules window, for
this one it is the only one that says "Loading disabled by Include/Exclude setting". Note that this may be irrelelant to my current problem, Im just theorizing. Heres the output:<br/>
<br/>
EditorApp.exe: Loaded ...EditorAppEditorApp.exe, No native symbols in symbol file.<br/>
EditorApp.exe: Loaded C:WindowsSystem32ntdll.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...mscoree.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...kernel32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...KernelBase.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...advapi32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...msvcrt.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...sechost.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...rpcrt4.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...mscoreei.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...shlwapi.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...gdi32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded...user32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...lpk.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...usp10.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...imm32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...msctf.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...clr.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...msvcr100_clr0400.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...mscorlib.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...mscorlib.dll<br/>
EditorApp.exe: Loaded ...ole32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...cryptbase.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...uxtheme.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...nlssorting.dll, Cannot find or open the PDB file<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...EditorAppEditorApp.exe, Symbols loaded.<br/>
EditorApp.exe: Loaded ...clrjit.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...oleaut32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...System.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...System.Drawing.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...System.Windows.Forms.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...System.Windows.Forms.dll<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...System.Drawing.dll<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...System.dll<br/>
EditorApp.exe: Loaded ...System.Configuration.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...System.Xml.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ImageAtBase0x73d30000, Loading disabled by Include/Exclude setting.<br/>
EditorApp.exe: Loaded ImageAtBase0x310000, Loading disabled by Include/Exclude setting.<br/>
EditorApp.exe: Unloaded ImageAtBase0x73d30000<br/>
EditorApp.exe: Loaded ...Microsoft.VisualStudio.Debugger.Runtime.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...Microsoft.VisualStudio.Debugger.Runtime.Impl.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...msvcr100.dll, Cannot find or open the PDB file<br/>
EditorApp.exe (Managed (v4.0.30319)): ...System.Configuration.dll<br/>
EditorApp.exe (Managed (v4.0.30319)): ...System.Xml.dll<br/>
EditorApp.exe (Managed (v4.0.30319)):...Microsoft.VisualStudio.Debugger.Runtime.dll<br/>
EditorApp.exe: Loaded ImageAtBase0x52fb0000, Loading disabled by Include/Exclude setting.<br/>
EditorApp.exe: Unloaded ImageAtBase0x52fb0000<br/>
EditorApp.exe: Loaded ...comctl32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...comctl32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...dwmapi.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...GdiPlus.dll, Cannot find or open the PDB file<br/>
<br/>
Any help would be appreciated.
View the full article
a file that I build from a C++ project. Here are the details:<br/>
<br/>
1) The error occurs in EngineDisplayForm.cs, line 138, which is where it calls NativeMethods.EditorMain. Here is the entire line of code inside that file:<br/>
<br/>
NativeMethods.EditorMain(hInstance, IntPtr.Zero, hwnd, 1, this.DisplayPanel.Width, this.DisplayPanel.Height);<br/>
<br/>
The code referenced in NativeMethods is:<br/>
<br/>
const string editorDllName = "Editor.dll";<br/>
[DllImport(editorDllName)]<br/>
public unsafe static extern int EditorMain(IntPtr instancePtrAddress, IntPtr hPrevInstancePtrAddress, IntPtr hWndPtrAddress, int nCmdShow, int screenWidth, int screenHeight);<br/>
<br/>
<br/>
2) The Editor.dll file is in the same directory as my EditorApp.exe, I build it there, and it is definitely found by the program. In fact, by executing this one line of code, Editor.dll is Loaded and then Unloaded 3 times. The output (note Ive abbreviated
the full path) from running this one line of code is:<br/>
<br/>
EditorApp.exe: Loaded ...EditorAppEditor.dll, Symbols loaded.<br/>
EditorApp.exe: Unloaded ...EditorAppEditor.dll<br/>
EditorApp.exe: Loaded ...EditorAppEditor.dll, Symbols loaded.<br/>
EditorApp.exe: Unloaded ...EditorAppEditor.dll<br/>
EditorApp.exe: Loaded ...EditorAppEditor.dll, Symbols loaded.<br/>
EditorApp.exe: Unloaded ...EditorAppEditor.dll<br/>
<br/>
<br/>
3) After these 3 Loads/Unloads, it produces the following exception:<br/>
<br/>
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)<br/>
<br/>
<br/>
4) Note that I have just done a full build of Editor.dll with the latest versions of all code<br/>
<br/>
<br/>
5) For my Editor project, I have specified during linking for it to have No Fixed Base Address (/FIXED:NO). When not specified I know it can present this type of problem for C# programs to link to C++ .dlls<br/>
<br/>
<br/>
6) Heres the full C# build with path abbreviations. Perhaps of particular note is "EditorApp.exe: Loaded ImageAtBase0x73d30000, Loading disabled by Include/Exclude setting." When I start the app, pause at a breakpoint, and open the Modules window, for
this one it is the only one that says "Loading disabled by Include/Exclude setting". Note that this may be irrelelant to my current problem, Im just theorizing. Heres the output:<br/>
<br/>
EditorApp.exe: Loaded ...EditorAppEditorApp.exe, No native symbols in symbol file.<br/>
EditorApp.exe: Loaded C:WindowsSystem32ntdll.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...mscoree.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...kernel32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...KernelBase.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...advapi32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...msvcrt.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...sechost.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...rpcrt4.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...mscoreei.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...shlwapi.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...gdi32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded...user32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...lpk.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...usp10.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...imm32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...msctf.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...clr.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: ...msvcr100_clr0400.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...mscorlib.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...mscorlib.dll<br/>
EditorApp.exe: Loaded ...ole32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...cryptbase.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...uxtheme.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...nlssorting.dll, Cannot find or open the PDB file<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...EditorAppEditorApp.exe, Symbols loaded.<br/>
EditorApp.exe: Loaded ...clrjit.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...oleaut32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...System.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...System.Drawing.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...System.Windows.Forms.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...System.Windows.Forms.dll<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...System.Drawing.dll<br/>
EditorApp.exe (Managed (v4.0.30319)): Loaded ...System.dll<br/>
EditorApp.exe: Loaded ...System.Configuration.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...System.Xml.ni.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ImageAtBase0x73d30000, Loading disabled by Include/Exclude setting.<br/>
EditorApp.exe: Loaded ImageAtBase0x310000, Loading disabled by Include/Exclude setting.<br/>
EditorApp.exe: Unloaded ImageAtBase0x73d30000<br/>
EditorApp.exe: Loaded ...Microsoft.VisualStudio.Debugger.Runtime.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...Microsoft.VisualStudio.Debugger.Runtime.Impl.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...msvcr100.dll, Cannot find or open the PDB file<br/>
EditorApp.exe (Managed (v4.0.30319)): ...System.Configuration.dll<br/>
EditorApp.exe (Managed (v4.0.30319)): ...System.Xml.dll<br/>
EditorApp.exe (Managed (v4.0.30319)):...Microsoft.VisualStudio.Debugger.Runtime.dll<br/>
EditorApp.exe: Loaded ImageAtBase0x52fb0000, Loading disabled by Include/Exclude setting.<br/>
EditorApp.exe: Unloaded ImageAtBase0x52fb0000<br/>
EditorApp.exe: Loaded ...comctl32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...comctl32.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...dwmapi.dll, Cannot find or open the PDB file<br/>
EditorApp.exe: Loaded ...GdiPlus.dll, Cannot find or open the PDB file<br/>
<br/>
Any help would be appreciated.
View the full article