Packing different DLL file for 32 and 64 bit targets

238 views
Skip to first unread message

Andrei F

unread,
Aug 16, 2017, 4:58:18 PM8/16/17
to Excel-DNA
I'm developing an addin that targets both 32 and 64 bit Excel. It has a new reference which is a native DLL; is it possible to make Excel-DNA pack a different version of this DLL for 32 and 64 addin packing targets?

Govert van Drimmelen

unread,
Aug 17, 2017, 2:41:42 AM8/17/17
to exce...@googlegroups.com
The Excel-DNA packing does not support native or mixed libraries (since .NET does not support loading these from memory).
So you'll need to make some other mechanism to store, and extract and load the files at runtime. You might embed them as resources in the C# assembly and then extract to a temp or user directory at runtime.
For a native library you might need to call LoadLibrary explicitly, before any of the P/Invoke calls are made.

-Govert

On 16 Aug 2017, at 23:00, Andrei F <fandre...@gmail.com> wrote:

I'm developing an addin that targets both 32 and 64 bit Excel. It has a new reference which is a native DLL; is it possible to make Excel-DNA pack a different version of this DLL for 32 and 64 addin packing targets?

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Andrei F

unread,
Aug 17, 2017, 10:44:09 AM8/17/17
to Excel-DNA
Thanks.

Sean Creighton

unread,
Aug 20, 2017, 6:12:14 PM8/20/17
to Excel-DNA
Hi

I created two dna files and edited the post build event like so

REM
REM  Pack the 32 xll 
REM 
xcopy "$(SolutionDir)packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna.xll" "$(TargetDir)MyLib-AddIn.xll*" /C /Y
"$(SolutionDir)packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)MyLib-AddIn.dna" /Y
REM
REM
REM  Pack the 64 xll
REM 
xcopy "$(SolutionDir)packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna64.xll" "$(TargetDir)MyLib-AddIn64.xll*" /C /Y
"$(SolutionDir)packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)MyLib-AddIn64.dna" /Y
REM
REM
REM  Copy the xlls
REM 
xcopy  "$(TargetDir)MyLib-AddIn64-packed.xll" "$(SolutionDir)_ExcelDeployment\MyLib-AddIn64-packed.xll*"/C /Y
xcopy  "$(TargetDir)MyLib-AddIn-packed.xll" "$(SolutionDir)_ExcelDeployment\MyLib-AddIn-packed.xll*"/C /Y
REM xcopy  "$(TargetDir)MyLib.dll" "$(SolutionDir)_ExcelDeployment\MyLib.dll*"/C /Y

I would then distribute an xla, that would open one of these two xlls depending on the bitiness of the users machine...... 

in VBA.....


Private Declare PtrSafe Function GetProcAddress Lib "kernel32" _
    (ByVal hModule As Long, _
    ByVal lpProcName As String) As Long

Private Declare PtrSafe Function GetModuleHandle Lib "kernel32" _
    Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long '()

Private Declare PtrSafe Function GetCurrentProcess Lib "kernel32" () As Long

Private Declare PtrSafe Function IsWow64Process Lib "kernel32" _
    (ByVal hProcess As Long, ByRef Wow64Process As Long) As Long

Public Function Check_OS_IS_64() As Boolean

    Dim Its64 As Long
    Dim handle As Long

    handle = GetProcAddress(GetModuleHandle("kernel32"), _
                   "IsWow64Process")

    If handle > 0 Then ' IsWow64Process function exists
        ' Now use the function to determine if
        ' we are running under Wow64

        IsWow64Process GetCurrentProcess(), Its64
    End If
    If Its64 = 1 Then
        CheckWhetherIts64 = True
    Else
        CheckWhetherIts64 = False
    End If
End Function

Public Function Check_Excel_IS_64() As Boolean
    Check_Excel_IS_64 = False
    #If Win64 Then
        Check_Excel_IS_64 = True
    #End If
End Function
Reply all
Reply to author
Forward
0 new messages