vc 6.0 program as a dll

I met the problem again.
In my program:

#define DllExport __declspec(dllexport)

/* Declare function */
extern "C" DllExport int fun1(int p1);
  .......

/* Function body */
extern "C" DllExport int fun1(int p1)
{
   .....
}

But in that two line about function header, it said
... error C2059: syntax error : 'string'

But in that two line, I don't write the token 'string'
So what happen? Is there any limit for that use?

Thanks
Ginaa
ginaaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
danelroismanConnect With a Mentor Commented:
Hi!

extern "C" in *.cpp file is superfluous.
Remove it.

Muth better to use in *.h dll file
extern "C"{

    //your functions prototypes


}
if you wtite you program in *.c file
extern "C" is unnecessary.

Check your code again.
If it not help send please full source.

Daniel
0
 
dhymesCommented:
#include <windows.h>

BOOL WINAPI DllEntryPoint (HINSTANCE hDLL, DWAORD dwReason,

LPVOID Researved)

{

switch (dwReason)

{

case DLL_PROCESS_ATTACH:

{

break;

}

case DLL_PROCESS_DETACG;

{

break;

}

}

return TRUE;

}

Add functions after the above template

 

int function1(void) // int MyBeep(void)

{

function1( ); //MessageBeep((WORD)-1);

return ... //return 1

}

Add prototypes at the beginning of MyDLL.cpp such as:

int function ( ); // int MyBeep(void) // intMyDelay(long wait)

....

3. Customise MyDLL.def

....

...

EXPORT

Function //MyBeep

Function //MyDelay

....

4. Build DLL
5. Remember that the name of DLL may be different from that of .cpp file name.

B++Builder

1. Use DLL Wizard

2. Revise the template (.cpp file)

#include <windows.h>
#pragma hdtstop
#define BUILD_DLL
#include "MyDLL.h"

3. Add codes to define function and classes after the template
4. Create "MyDLL.h" file using template:

#ifndef _MYDLL_H
#define _MYDLL_H
#if defined(BUILD_DLL)
# define DLL_EXP __declspec(dllimport)
#else
# if defined(BUILD_APP)
# define DLL_EXP __declspec(dllexport)
# else
# define DLL_EXP
# endif
#endif

extern "C" void DLL_EXP SayHello(HWND)

class DLL_EXP MyClass {

public:

MyClass(HWND, hwnd);

Void SaySomething(char* text);

Viod Beep();

Private:

HWND hwnd;

};

#endif

5. Generate .lib using implib.exe

 

implib MyDll.lib MyDll.dll

 

 

PBDLL DLL

$COMPILE DLL

DEFINE A-Z

%one=1

FUNCTION AddOne(BYVAL XAS INTEGER) EXPORT AS INTEGER

Function = X + %ONE

END FUNCTION

 

$COMPILE

 

Calling DLL

MSVC

1. Add the lines to the top of the calling progarm (.cpp)

            HINSTANCE gLibMyDLL = NULL;

            Typedef int (*FUNCTION)(..) // Typedef int (*MYBEEP)(void);

            FUNCTION Function; // MYBEEP MyBeep;

            ...

2. Load DLL

 

gLibMyDLL = LoadLibrary("MyDLL.DLL");

3. Get the address of the function

 

Function=(FUNCTION)GetProcAddress(gLibMyDLL, "Function");

// Function=(MYBEEP)GetProcAddress(gLibMyDLL, "MyBeep");

4. Call the function

 

Function().. //MyBeep(); //MyDelay(500);

B++Builder Calling DLL

1. Add the lines to top of program:

#define BUILD_APP

#include "MyDll.h"

2. Add DLL import libaray (.lib) to the project. (View|Project Manager ->Add Unit...)

3. The above is for static loading. For dynamic loading, use Windows API LoadLibrary() to load and FreeLibrary() to unload. Also need to obtain address from
GetProcAddress().

 

VB Calling DLL

Declare Function AddOne% Lib "ADDONE.DLL" (ByVal x%)

A%=4

B%=AddOne%(a%)


0
 
Oliver_DornaufCommented:
I think you use the wrong Syntax. Try

-> import or export in .h
#ifdef build_dll
#define DllExport __declspec(dllexport)
#else
#define DllExport __declspec(dllimport)
#endif

extern "C" {
 DllExport int fun1(int p1);
}

.......
Implementation:
int fun1(int p1)
{
 ....
}


 
0
 
ginaaAuthor Commented:
Sorry, but I ever try to put my code into some sample dll project and it work.
So I think it should be some compiler or link setting problem.

Thanks
Ginaa
0
 
danelroismanCommented:
Thanx for the points!
Daniel
0
All Courses

From novice to tech pro — start learning today.