Re: Help with LoadLibrary and DLL
- From: "Philip Borghesani" <philip_borghesani@xxxxxxxxxxxxxx>
- Date: Mon, 21 Dec 2009 11:52:35 -0500
"omegayen " <omegayen@xxxxxxxxxxxxx> wrote in message news:hgmr02$pe7$1@xxxxxxxxxxxxxxxxxxxxx
Hi,
I am try to follow the example on http://guoliangye.com/2009/01/21/how-to-write-a-dll-in-cc-and-call-it-in-matlab/
I created two files
dll1.h
#ifndef MY_API
#define MY_API extern "C" __declspec(dllexport)
#endif
MY_API int add(int a, int b);
MY_API int sub(int a, int b);
dll1.cpp
#ifndef MY_API
#define MY_API extern "C" __declspec(dllexport)
#endif
#include "dll1.h"
int add(int a,int b)
{
return a + b;
}
int sub(int a,int b)
{
return a - b;
}
I think used Visual Studio 2008 SP1 Version 9 Pro on Windows Vista 64 bit using Matlab 2009b 64 bit to compile a x64 dll file.
I then use load library function such as loadlibrary('D:\dll1\Debug\dll1.dll', 'D:\dll1\dll1.h'); in MATLAB
when I do this i get the error message
??? Error using ==> loadlibrary at 422
Building SimpleDll_thunk_pcwin64 failed. Compiler output is:
SimpleDll_thunk_pcwin64.c
C:\Users\user_name_removed\Documents\Visual Studio 2008\Projects\SimpleDll\x64\Debug\SimpleDll.h(4) : error C2059: syntax error :
'string'
C:\Users\user_name_removed\Documents\Visual Studio 2008\Projects\SimpleDll\x64\Debug\SimpleDll.h(5) : error C2059: syntax error :
'string'
can anyone help tell me why I am getting error C2059 syntax error 'string' I suspect it has something to do with the extern "C"
__declspec(dllexport) line but am not sure how to change things up to work. thanks
Try changing dll1.h to:
#ifndef MY_API
#define MY_API
#endif
MY_API int add(int a, int b);
MY_API int sub(int a, int b);
The guard block around the #define statement in your cpp code is not needed but will not harm anything.
Phil
.
- Follow-Ups:
- Re: Help with LoadLibrary and DLL
- From: omegayen
- Re: Help with LoadLibrary and DLL
- References:
- Help with LoadLibrary and DLL
- From: omegayen
- Help with LoadLibrary and DLL
- Prev by Date: Re: fopen with path
- Next by Date: Re: function not working
- Previous by thread: Help with LoadLibrary and DLL
- Next by thread: Re: Help with LoadLibrary and DLL
- Index(es):
Relevant Pages
|