Question

I want Sketchup can import muliple files. But unfortunately, Sketchup API dosen't support it. So i created one dll library. It call Window API function: GetOpenFileName for displaying multi-select dialog, get selected file names and display them in formatted string (selected directory | filename1 |filename2...). Then i put it and Win32API.so into Plugin folder of Sketchup. But when i open Sketchup, it display error:

Error Loading File GetProcAddress: ShowDialog or ShowDialogA (ShowDialog is one function of my dll )

Here is my code in dllmain.cpp (C++ code)

#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] = '\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] != '\0')
        {
            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]='\0';
}



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

Here is my script in ruby file.

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: %s\n",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

I use Visual Studio 2012 to build dll and My Sketchup is Sketchup 8

Any suggestions would be appreciated.

Was it helpful?

Solution

The export needs to be C exports (without C++ name mangling). Try defining the EXPORT macro like this:

#define EXPORT extern "C" _declspec(dllexport)

or define the exported functions inside extern "C"

extern "C" {

// Exported functions here.

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top