DLL Probleem

Status
Niet open voor verdere reacties.

C Windows

Gebruiker
Lid geworden
22 nov 2008
Berichten
159
Hallo allemaal,
ik heb een probleempje met DLLs in C++ (ik gebruik overigens Visual Studio '08).

Ik heb een CLR Windows Form Application en een CLR Class Library (DLL) in een solution. In de DLL heb ik het bestand Functions.h:

Code:
#define FUNCTIONSAPI extern "C" __declspec(dllexport)

int iResult;

int Add(int iOne, int iTwo) {
	iResult = iOne + iTwo;
	return iResult;
}

en in de Windows Forms App het bestand Funcs.h:

Code:
#ifndef FUNCTIONSAPI
#else
#define FUNCTIONSAPI extern "C" __declspec(dllimport)
#endif

FUNCTIONSAPI int iResult;
FUNCTIONSAPI int Add(int iOne, int iTwo);

Ik probeer in frmMain.h deze code uit te voeren:

Code:
#include "Funcs.h"

- Snip -

void frmMain_Load(System::Object^  sender, System::EventArgs^  e) {
    this->Text = Add(10, 34).ToString();
}

maar dat levert de volgende errors op:

error C2086: 'int FUNCTIONSAPI' : redefinition Funcs.h
error C2144: syntax error : 'int' should be preceded by ';' Funcs.h
error C2144: syntax error : 'int' should be preceded by ';' Funcs.h
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Funcs.h
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int Funcs.h

Heeft iemand hier een oplossing voor?
 
Even over je eerste code:

#define FUNCTIONSAPI extern "C" __declspec(dllexport)

int iResult;

int Add(int iOne, int iTwo) {
iResult = iOne + iTwo;
return iResult;
}


Die iResult is overbodig, je kunt net zo goed doen: return iOne+iTwo...
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan