DLL 继承类接口的提供! 急解决方法

DLL 继承类接口的提供!!! 急

怎么把带有继承关系的类提供给DLL调用者(APP)端使用?
因为DLL代码是APP端独立出来的,按照C++接口调用方式代码量很大,所以尽量不要改变APP端接口调用方式。

整个工程比较大,针对现在存在的问题,写一个小小的代码示例。

/*DLL,工程名dll*/
// 文件 CBase.h CImpl.h
//     CBase.cpp CImpl.cpp dll.cpp dll.def
// Include文件夹 ICBase.h ICImpl.h

// CBase.h
#ifndef __CBASE_H__
#define __CBASE_H__

#include "Include/ICBase.h"

class CBase : public ICBase
{
  public:
     CBase() {}
     ~CBase() {}
  public:
     virtual void test_cbase_virtual();
     vodi test_cbase_normal();
}

#endif

// CBase.cpp
#include "stdafx.h"
#include "CBase"

void CBase::test_cbase_virtual()
{
  printf("\ntest_cbase_virtual...");
}

void CBase::test_cbase_normal()
{
  printf("\ntest_cbase_normal...");
}

// ICBase.h
#ifndef __ICBASE_H__
#define __ICBASE_H__

class ICBase
{
  virtual void test_cbase_virtual() = 0;
  virtual void test_cbase_normal() = 0;
}

#endif

// CImpl.h
#ifndef __CIMPL_H__
#define __CIMPL_H__

#include "Include/ICImpl.h"

class CImpl : public ICImpl, public CBase
{
public:
  CImpl() {}
  ~CImpl() {}
public:
  virtual void test_virtual();
  void test_normal();
}
#endif

// CImpl.cpp
#include "stdafx.h"
#include "CImpl.h"

void CImpl::test_virtual()
{
  printf("\ntest_virtual");
}

void CImpl::test_normal()
{
  printf("\ntest_noraml");
}

// ICImpl.h
#ifndef __ICIMPL_H__
#define __ICIMPL_H__

class ICImpl
{
  public:
    virtual void test_virtual() = 0;
    virtual void test_normal() = 0;
}

#endif

// dll.cpp
#include "stdafx.h"
#include "CImpl.h"

BOOL APIENTRY DllMain()....
CImpl* g_pcImpl = NULL;
CImpl* CreateImpl()
{
  if (NULL == g_pcImpl)
  {
      g_pcImpl = new CImpl();
  }
  return g_pcImpl;
}
void DestoryImpl()
{
  if (g_pcImpl)
  {
   delete g_pcImpl;
   g_pcImpl = NULL;
  }
}

// dll.def
EXPROTS
  CreateImpl
  DestoryImpl

/*APP端, DLL提供Include文件夹给APP端*/

#include "../../dll/include/ICmpl.h"

void test_app_dll()
{
  HMODULE hdll = LoadLibrary(L"dll.dll");

 typedef ICImpl* (*fnCreate)();
 typedef void (*fnDestory)();

 fnCreate fn_Create = (fnCreate)(GetProcAddress(hdll, L"CreateImpl"));
 fnDestory fn_Destory = (fnDestory)(GetProcAddress(hdll, L"DestoryImpl"));

 ICImpl* pcImpl = fn_Create();
 if (pcImpl)
 {
  pcImpl->test_virtual(); // 正常调用
  pcImpl->test_normal(); // 正常调用
  // 在此处想调用CBase的方法
 }
 fn_Destory();

 FreeLibrary(hdll);
}


如果想调用CBase的方法,Include该怎么导出?
class ICImpl : public ICBase这样不行,ICBase无法成为纯虚接口。

------解决方案--------------------
你用了ICImpl,那么ICImpl其实跟ICBase一点关系都没有,当然就用不了。
fn_Create();返回的对象继承了ICImpl,CBase,就可以调用。

------解决方案--------------------
使用静态调用方式,include对应的头文件,然后使用
#pragma comment(lib,"Win32_Dll.lib")
来引用对应的lib库,这样就可以直接使用dll中的类了
------解决方案--------------------
你只导出了IClmpl?其他都没有导出?如果是这样没啥办法
------解决方案--------------------
就算有ICBase也没有用,就你的写好两个接口还是私有的。