Ruby Sketchup Ruby中调用dll库时出错



我希望Sketchup可以导入多个文件。但不幸的是,Sketchup API不支持它。所以我创建了一个dll库。它调用Window API函数:GetOpenFileName来显示多选对话框,获取选定的文件名并以格式化字符串(选定目录|文件名1 |文件名2…)显示。然后我将其和Win32API.so放入Sketchup的插件文件夹中。但当我打开Sketchup时,它显示错误:

加载文件GetProcAddress:ShowDialog或ShowDialogA时出错(ShowDialog是我dll的一个函数)

这是我在dllmain.cpp(C++代码)中的代码

#define EXPORT _declspec(dllexport)
HWND hDlg = NULL;
wchar_t* buffer = new wchar_t[32768];
EXPORT void ShowDialog(void)
{
OPENFILENAME ofn;
wchar_t szFile[32768];
// Initialize OPENFILENAME
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hDlg;
ofn.lpstrFile = (wchar_t*)szFile;
ofn.lpstrFile[0] = '';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags =  OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_EXPLORER;
if(GetOpenFileName(&ofn) == TRUE)
{
if(szFile[ofn.nFileOffset-1] != '')
{
wcscpy_s(buffer,sizeof(szFile),szFile);
}
else
{
//Multi-select
wchar_t* p= szFile;
int i =0;
while(*p)
{
wchar_t* temp = new wchar_t[1024];
//Copy p into temp
wcscpy_s(temp,1024,p);
if(i==0)
{
wcscpy_s(buffer,1024,temp);
}
else
{
wcscat_s(buffer,1024,temp);
}
wcscat_s(buffer, sizeof(buffer) * wcslen(buffer), L"|");
i++;
p += lstrlen(p) + 1;
}
}
int len = wcslen(buffer);
buffer[len]='';
}

EXPORT void GetResult(char* pString)
{
int len = wcslen(buffer);
for(int i =0 ; i < wcslen(buffer);i++)
{
pString[i] = (char)buffer[i];
}
pString[len]='';
}

这是我在ruby文件中的脚本。

require 'sketchup.rb'
require "Win32API"
path = Sketchup.find_support_file("Plugins\")
#my dll has name MultiUploadProject.dll
mydll = path + "\MultiUploadProject.dll"
if (!FileTest.exist?( mydll ) )
UI.messagebox(sprintf("MultiUploadProject.dll not found in SketchUp plugins folder: %sn",mydll))
end
ShowDialog = Win32API.new(mydll,"ShowDialog",["V"],"V")
GetResult = Win32API.new(mydll,"GetResult",["P"],"V")
def load_dialog
ShowDialog.call
string = " " * 32768
GetResult.call(string)
end

我使用Visual Studio 2012构建dll,我的Sketchup是Sketchup 8

如有任何建议,我们将不胜感激。

导出需要是C导出(没有C++名称篡改)。尝试定义EXPORT宏如下:

#define EXPORT extern "C" _declspec(dllexport)

或在外部"C"中定义导出的函数

extern "C" {
// Exported functions here.
}

相关内容

  • 没有找到相关文章

最新更新