Ruby extension module using C/C++
-
Just an FYI, I have used SWIG to generate Ruby extensions from C++ fairly easily.
-
You wouldn't have an example or two would you?
And are we talking cross platform? -
You can download SWIG at http://www.swig.org/ and build some of the Ruby examples. Then you just put the compiled dll in the Ruby search path for SketchUp and require it like a Ruby script. To be binary compatible with the SketchUp Ruby you should compile with MSVC on Windows and gcc on Mac. You do have to compile separately for each platform, the makefiles/Visual Studio projects are not cross platform so you either need to maintain separate projects or use something like CMake (which is a cross platform makefile generator).
I don't know if the dll will make it through as an attachment (rename 'example.txt' to 'example.dll') but I compiled the example 'C:\SWIG\Examples\ruby\class' using Visual Studio Express 2009 and attached the dll. You can put it in the plugins directory and use the following script:
###########################################
require 'example'c = Example::Circle.new(1)
puts c
s = Example::Square.new(1)
puts s
###########################################Hope that helps,
Dan
-
In case anyone tries this on Windows, this post helped me out when I was first starting:
http://apocryph.org/2007/06/16/totally_bullshit_ruby_extension_experience_windows/
-
@macumber said:
To be binary compatible with the SketchUp Ruby you should compile with MSVC on Windows and gcc on Mac. You do have to compile separately for each platform, the makefiles/Visual Studio projects are not cross platform so you either need to maintain separate projects or use something like CMake (which is a cross platform makefile generator).
Visual C++ Express 2010 - will that work? Or does it require a particular version?
-
I think the main things are to link against the same version of the Microsoft Runtime library (MSVCRT.DLL, looks like Sketchup 7.1 uses MSVCRT 7.0.2600.5512) and same version of Ruby (1.8.0, although I have used 1.8.6 without problem so far...). There is a fork between MSVC and MinGW camps for Ruby on Windows, make sure you don't try to link against the MinGW build of Ruby.
-
And how can I obtain this exact DLL version?
(I'm very green to C/C++) -
@dan rathbun said:
There is strange effect when MS Common Controls 6 are ON: the images for the 4 buttons on the left of the Sketchup statusbar don't render (at least on XP, but I don't use those buttons anyway, so it's OK with me.)
Are they subclassed perhaps?
-
@thomthom said:
Are they subclassed perhaps?
Not as far as I can tell.
UI-Spy shows them as just 'ContolType.Button', ClassName 'Button'
They are each wrapped inside an edit control, strange because the toolbar buttons are not and they render fine. -
@dan rathbun said:
There are two DLLs in the Sketchup folder (msvcp.dll, msvcr.dll).
I do not have these. Closest I got is
C:\Program Files (x86)\Google\Google SketchUp 7
-
-
@thomthom said:
And how can I obtain this exact DLL version?
There are two DLLs in the Sketchup folder (msvcp71.dll, msvcr71.dll). These should have been copied to the Windows/System32 folder, and registered. If you explore the Windows/System32 folder and click on the Name column, all the "msvc*" DLL files will be listed together. You can hover over them to see their versions (or right click in the column headers, choose "More..." and check "Product Version" if you always want to see version displayed. You may have to have "Remember each folder's view settings" set in Menu: Tools > Folder Options... > View tab > Advanced settings: listbox.)
EDIT: corrected filenames in 1st sentence.If anyone is interested, attached find a zip with 3 exported 7.x Sketchup RT_MANIFEST files. (Used MSVS to export them,) and gave them a filename with the SU version, and XML extension so they will be properly lexed in editors. (I suppose you could register .manifest extension to use the XML lexer in your editor's settings.).7.x manifest files (XML)
Did you know?? You can modify manifest files, ie, add dependant assemblies; rename them progname.exe.manifest (where progname is the name of the program,) and put them in the same folder as the executable. When the program loads, Windows automatically looks for an external manifest file, and loads it. An external manifest file trumps a program's internal resource manifest, (so make sure it has the same entries as the internal one, ie: export it using a resorce editor such as Visual Studio.)I use an external manifest to force Sketchup to use MS Common Controls ver 6 (aka XP Styled Controls,) instead of those old ugly ver 5 Controls that look like the ones in Windows 3.x !! Vista users might benefit from using Common Controls ver 6.1, but not sure (do not have Vista.)
Here's the <dependancy> XML tag to add for ver 6.0 Controls:<dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity> </dependentAssembly> </dependency>
There is strange effect when MS Common Controls 6 are ON: the images for the 4 buttons on the left of the Sketchup statusbar don't render (at least on XP, but I don't use those buttons anyway, so it's OK with me.)
-
404 - files not found.
only files starting with M in my SU folder is:
-
@thomthom said:
404 - files not found.
Well.. sorry. I suppose I might have copied them in there manually to try and get SU to use those versions. It seems I remember a previous post awhile back about SU using old msvcrt versions.
Anyway, the point of the post was where are the DLLs. They are usually put by the application installer into the Windows/System32 folder and registered using regsvr32.exe, but normally the installer is not supposed to overwrite newer versions with older versions. If an application must use and older version, it can keep a local copy in it's program folder and specifically load the local copy. (Which may be how I ended up with copies in the SU folder, I was trying to see SU would use those instead of the ones in my Windows/System32 folder. I have a problem with the MCVCRT and I cannot update several applications, including MS Visual Studio and .NET; something has gotten 'out of whack' on my machine.)
Advertisement