64,637
社区成员
发帖
与我相关
我的任务
分享
#ifdef XYZLIBRARY_EXPORTS
#define XYZAPI __declspec(dllexport)
#else
#define XYZAPI __declspec(dllimport)
#endif
#ifdef __cplusplus
# define EXTERN_C extern "C"
# define XYZHANDLE IXyz*
struct IXyz
{
virtual int Foo(int n) = 0;
virtual void Release() = 0;
};
#endif
EXTERN_C XYZAPI int hzf (int);
EXTERN_C XYZAPI XYZHANDLE hzfXyz (VOID);
#include "stdafx.h"
#include "stdio.h"
#include "XyzLibrary.h"
class XyzImpl : public IXyz
{
public:
int Foo(int n);
void Release();
};
int XyzImpl::Foo(int n)
{
printf("Foo called....%d\n",n);
return n * n;
}
void XyzImpl::Release()
{
delete this;
}
XYZHANDLE hzfXyz()
{
printf("\n\nhzfXyz() called ....\n");
return new XyzImpl;
}
int hzf(int n)
{
printf("\n\nhzf(int) called ....\n");
XyzImpl *xyz = new XyzImpl;
return xyz->Foo(n);
}
#include <stdio.h>
#include "XyzLibrary.h"
int main(int ,char** )
{
IXyz *xyz = hzfXyz();
printf(" hzfXyz call: %d\n" , xyz->Foo(5));
printf(" hzf call: %d\n" , hzf(8));
return 0;
}