Last week, i searched & tried a lot in freebasic to get the com object of a running excel file. But Disphelper library only gives a CreateObject function. It is not giving a GetObject function. At last, Jose Roca gave me a function to get an IDispatch ptr of the running excel object. But i failed to get the com object and related properties with that pointer. So i tried to find that feature in another language. Finally, i got a new language called Nim. Python like syntax and C like speed. Actually it compiles to C. So far so good. I have created a Nim dll to get the ActiveWindow caption of an excel file. Nim string is unicode. The One and only function in dll will return a Nim String.
How to use this dll in FreeBasic.
I have tried this but failed. Compiler says this ---- "cannot find -lDllTest.dll" I am sure that my dll's name is "DllTest", not "lDllTest".
Code: Select all
#Inclib "DllTest"
#Include Once "Afx/CWSTR.inc"
#Include "windows.bi"
Extern "C"
Declare Function GetExcelWinTitle Lib "DllTest.dll"() As String
End Extern
#Macro MsgBox(sMsg)
MessageBoxW(0, Str(sMsg), "Message", MB_OK)
#Endmacro
Dim exCap As CWSTR= GetExcelWinTitle()
MsgBox(exCap )
Sleep
Code: Select all
import winim/com
proc GetExcelWinTitle*() : string {.stdcall, exportc:"GetExcelWinTitle", dynlib.} =
try :
var exl = GetObject("", "Excel.Application")
result = exl.ActiveWindow.Caption
except :
echo "Excel is not opned"