Click here to Skip to main content
15,881,803 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: encoding/decoding prob Pin
Farhan Noor Qureshi26-Oct-05 18:28
Farhan Noor Qureshi26-Oct-05 18:28 
GeneralRe: encoding/decoding prob Pin
toto567826-Oct-05 20:36
toto567826-Oct-05 20:36 
GeneralRe: encoding/decoding prob Pin
Farhan Noor Qureshi27-Oct-05 6:55
Farhan Noor Qureshi27-Oct-05 6:55 
GeneralRe: encoding/decoding prob Pin
toto567827-Oct-05 23:01
toto567827-Oct-05 23:01 
Question'DragDrop', 'throw' and 'Application.ThreadException' Pin
__alex25-Oct-05 22:55
__alex25-Oct-05 22:55 
AnswerRe: 'DragDrop', 'throw' and 'Application.ThreadException' Pin
Daniel Grunwald27-Oct-05 5:00
Daniel Grunwald27-Oct-05 5:00 
GeneralRe: 'DragDrop', 'throw' and 'Application.ThreadException' Pin
__alex27-Oct-05 5:15
__alex27-Oct-05 5:15 
QuestionConverting old C library into .NET Pin
wgaiw25-Oct-05 5:03
wgaiw25-Oct-05 5:03 
I have the code of an old C library that acts as a very basic add-on module for FS (MS Flight Simulator). Since I'm just a simple .NET developer I have no clue how to convert this code into .NET code, in a way it still is compatible with FS. I thought the best solution was to convert it into a managed C++ library, and include this library in my C# project. However, since I'm not a very experienced C/C++ developer I don't know how to do this. Converting it directly into C# code would be perfect, ofcourse, but I don't know if that's possible.

Is this possible at all? Maybe someone can point me in the right direction? I would be very grateful!

This code just adds a menu item to the FS menubar.

The header file:
<br />
// MODULE.H<br />
// (c) 2004 - Cyril Hruscak<br />
#ifndef	__FS_MODULE_H__<br />
#define	__FS_MODULE_H__<br />
<br />
#define	DLLEXPORT	__declspec(dllexport)<br />
#define	FSAPI	__stdcall<br />
<br />
/**<br />
 * This is the module's import table definition.<br />
 */<br />
typedef struct _MODULE_IMPORT {<br />
	struct {<br />
		int fnID;<br />
		PVOID fnptr;<br />
	} IMPORTSentry;<br />
	struct {<br />
		int fnID;<br />
		PVOID fnptr;<br />
	} nullentry;<br />
} MODULE_IMPORT;<br />
<br />
/**<br />
 * This is the module's export table definition<br />
 */<br />
typedef struct _MODULE_LINKAGE {<br />
	int ModuleID;<br />
	void (FSAPI *ModuleInit)(void);<br />
	void (FSAPI *ModuleDeinit)(void);<br />
	UINT32 ModuleFlags;<br />
	UINT32 ModulePriority;<br />
	UINT32 ModuleVersion;<br />
	PVOID ModuleTable;<br />
} MODULE_LINKAGE;<br />
<br />
#endif	/* __FS_MODULE_H__ */<br />


The main file:
<br />
// MAIN.C<br />
// (c) 2004 - Cyril Hruscak<br />
#include <windows.h><br />
#include "module.h"<br />
<br />
/*<br />
 * We define just basic interface to the flight simulator so it will be<br />
 * able to load the module.<br />
 */<br />
DLLEXPORT MODULE_IMPORT ImportTable = {<br />
	{0x00000000, NULL},<br />
	{0x00000000, NULL}<br />
};<br />
<br />
void FSAPI module_init(void) {}<br />
void FSAPI module_deinit(void) {}<br />
<br />
DLLEXPORT MODULE_LINKAGE Linkage = {<br />
	0x00000000,<br />
	module_init,<br />
	module_deinit,<br />
	0,<br />
	0,<br />
	0x0900,	// FS2004 version (use 0x0800 for FS2002)<br />
	NULL<br />
};<br />
<br />
// The standard window procedure used by the flight simulator<br />
WNDPROC oldWndProc;<br />
<br />
// Flight simulator main window handle<br />
HWND hFSimWindow;<br />
<br />
#define	MENU_ENTRY	"My Mo&dule"<br />
#define	ID_MY_MENUITEM	40001<br />
<br />
/**<br />
 * Main window procedure that is called by the flight simulator to process<br />
 * incoming window messages.<br />
 */<br />
LRESULT CALLBACK FSimWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)<br />
{<br />
	switch (uMsg) {<br />
		case WM_NCPAINT:<br />
			{<br />
				HMENU hMenu, hMyMenu;<br />
<br />
				hMenu = GetMenu(hwnd);<br />
				if (hMenu != NULL) {<br />
					int i;<br />
					// Look for our menu entry in the main menu.<br />
					for (i = 0; i < GetMenuItemCount(hMenu); i++) {<br />
						char buf[128];<br />
						GetMenuString(hMenu, i, buf, 128, MF_BYPOSITION);<br />
						if (strcmp(buf, MENU_ENTRY) == 0) {<br />
							// It is already here, we do not need to add it again<br />
							break;<br />
						}<br />
					}<br />
					if (i < GetMenuItemCount(hMenu)) {<br />
						// It is already here, we do not need to add it again<br />
						break;<br />
					}<br />
					/* Create new menu. NOTE: It seems that this will be<br />
					 * reached more times, so we cannot save the handle, because<br />
					 * in such case it could be destroyed and we will not have<br />
					 * any access to it in the simulator.<br />
					 */<br />
					hMyMenu = CreateMenu();<br />
					AppendMenu(hMyMenu, MF_STRING | MF_ENABLED, ID_MY_MENUITEM, "My &First Menu Entry");<br />
					// add the created menu to the main menu<br />
					AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hMyMenu, MENU_ENTRY);<br />
				}<br />
			}<br />
			break;<br />
		case WM_COMMAND:<br />
			if (LOWORD(wParam) == ID_MY_MENUITEM) {<br />
				// Add your code here<br />
				MessageBox(hwnd, "It works!", "HURA", MB_OK | MB_ICONEXCLAMATION);<br />
				return 0;<br />
			}<br />
			break;<br />
	}<br />
	// Call the original window procedure to handle all other messages<br />
	return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam);<br />
}<br />
<br />
/**<br />
 * Entry point of the DLL.<br />
 */<br />
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)<br />
{<br />
	switch (fdwReason) {<br />
		case DLL_PROCESS_ATTACH:<br />
			hFSimWindow = FindWindow("FS98MAIN", NULL);<br />
			oldWndProc = (WNDPROC)SetWindowLong(hFSimWindow, GWL_WNDPROC, (LONG)FSimWindowProc);<br />
			break;<br />
	}<br />
	return TRUE;<br />
}<br />



From what I understand, the DllMain function is the most problematic part, since .NET doesn't support DllMain??

Thank you in advance for your help! Smile | :)

Joost
AnswerRe: Converting old C library into .NET Pin
Christian Graus25-Oct-05 15:55
protectorChristian Graus25-Oct-05 15:55 
QuestionRe: Converting old C library into .NET Pin
wgaiw26-Oct-05 11:35
wgaiw26-Oct-05 11:35 
AnswerRe: Converting old C library into .NET Pin
Christian Graus26-Oct-05 11:38
protectorChristian Graus26-Oct-05 11:38 
Questiondisco Pin
tekken2224-Oct-05 9:26
tekken2224-Oct-05 9:26 
QuestionIlease and ISponsor why need for both ? Pin
tekken2224-Oct-05 8:58
tekken2224-Oct-05 8:58 
QuestionCall COM+ services on other machines with my local .NET framework Pin
olmo24-Oct-05 8:20
olmo24-Oct-05 8:20 
QuestionRemote debugging : Windows form apps Pin
Md Saleem Navalur24-Oct-05 0:39
Md Saleem Navalur24-Oct-05 0:39 
QuestionImage Converting Pin
idris cinn23-Oct-05 20:46
idris cinn23-Oct-05 20:46 
AnswerRe: Image Converting Pin
Christian Graus25-Oct-05 15:57
protectorChristian Graus25-Oct-05 15:57 
QuestionProcedure to Install Visual Studio.net Pin
Anonymous23-Oct-05 19:56
Anonymous23-Oct-05 19:56 
AnswerRe: Procedure to Install Visual Studio.net Pin
Dave Kreskowiak24-Oct-05 4:41
mveDave Kreskowiak24-Oct-05 4:41 
GeneralRe: Procedure to Install Visual Studio.net Pin
Anonymous24-Oct-05 21:14
Anonymous24-Oct-05 21:14 
GeneralRe: Procedure to Install Visual Studio.net Pin
Dave Kreskowiak25-Oct-05 1:16
mveDave Kreskowiak25-Oct-05 1:16 
QuestionXML Style commnets in .Net Pin
sheerprogrammer23-Oct-05 19:45
sheerprogrammer23-Oct-05 19:45 
QuestionRunning .NET applications on computers without the framework Pin
mihai_152922-Oct-05 11:25
mihai_152922-Oct-05 11:25 
AnswerRe: Running .NET applications on computers without the framework Pin
Dave Kreskowiak22-Oct-05 13:56
mveDave Kreskowiak22-Oct-05 13:56 
GeneralRe: Running .NET applications on computers without the framework Pin
mihai_152923-Oct-05 0:29
mihai_152923-Oct-05 0:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.