C++ 从库类函数导出DLL字符串

C++ 从库类函数导出DLL字符串,c++,class,dll,.lib,C++,Class,Dll,.lib,我正试图从我的DLL中导出一个字符串,该字符串来自我的DLL中包含的库。我的DLL包含CMMCore.lib库,还有一个CMMCore类具有getDeviceAdapterNames()函数。此函数返回一个字符串 < > >强>我的C++代码到LabRy(.LIB)是:>/P> #include "PluginManager.h" ... std::vector<std::string> CMMCore::getDeviceAdapterNames() throw (CMMError

我正试图从我的DLL中导出一个字符串,该字符串来自我的DLL中包含的库。我的DLL包含CMMCore.lib库,还有一个CMMCore类具有
getDeviceAdapterNames()
函数。此函数返回一个字符串

< > >强>我的C++代码到LabRy(.LIB)是:>/P>
#include "PluginManager.h"
...
std::vector<std::string> CMMCore::getDeviceAdapterNames() throw (CMMError)
{
      return pluginManager_->GetAvailableDeviceAdapters();
}
...
#include <MMCore.h>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <vector>
using namespace std;
EXPORT void getDevice_dll(char* input_string) 
{   
    CMMCore * v = new CMMCore;
    v->CMMCore::getDeviceAdapterNames();
    memcpy(input_string, v, 20);
}
我的DLL代码是:

#include "PluginManager.h"
...
std::vector<std::string> CMMCore::getDeviceAdapterNames() throw (CMMError)
{
      return pluginManager_->GetAvailableDeviceAdapters();
}
...
#include <MMCore.h>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <vector>
using namespace std;
EXPORT void getDevice_dll(char* input_string) 
{   
    CMMCore * v = new CMMCore;
    v->CMMCore::getDeviceAdapterNames();
    memcpy(input_string, v, 20);
}
#包括
#包括
#包括
#包括
使用名称空间std;
导出无效getDevice\u dll(字符*输入\u字符串)
{   
CMMCore*v=新的CMMCore;
v->CMMCore::getDeviceAdapterNames();
memcpy(输入_字符串,v,20);
}
我想将CMMCore::getDeviceAdapterNames中的字符串放到*(input_string),但它不起作用


有没有办法将字符串从
CMMCore::getDeviceAdapterNames
放到我自己命名的指针或变量值?

作为
CMMCore::getDeviceAdapterNames
返回字符串向量,代码应该是:

    //max_input_string_size <- size of the input buffer.
    //return the number of device found and saved in input_string, -1 if error.
    EXPORT int getDevice_dll(char* input_string, int max_input_string_size )
    {
            std::vector<std::string> modules;
            try {
                    //if getDeviceAdapterNames was declared as a static member function
                    modules = CMMCore::getDeviceAdapterNames();

                    //if non static member function:
                    modules = CMMCore().getDeviceAdapterNames();

            }catch( CMMError &e ){
                    //handle the error here
                    return -1; //error DEVICE_DUPLICATE_LIBRARY
            }

            string strOutput;

            //change this if your application use other separator(e.g : "\r\n" or "," or "|")
            string strSeparator(";");
            for(int i = 0; i < modules.size(); i++ ){
                    strOutput += modules[i] + strSeparator;
            }
            strncpy( input_string, strOutput.c_str(), max_input_string_size );
            return modules.size();

    }

//max\u input\u string\u size我也尝试std::vector input\u string=CMMCore::getDeviceAdapterNames;这还是不行,太棒了。非常感谢你。这是我的工作。你以前用过micro manager开源软件吗?@Karas不客气,我以前没用过micro manager软件,但它看起来很有趣。