Link to home
Start Free TrialLog in
Avatar of ginaa
ginaa

asked on

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
Avatar of dhymes
dhymes

#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%)


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)
{
 ....
}


 
Avatar of ginaa

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of danelroisman
danelroisman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx for the points!
Daniel