how does one call a cobra .dll method from the excel (2002, in this case) VBA editor, and hopefully from an excel spreadsheet as a user-defined function, as well?
well, i started with this promising-looking guide:
http://richnewman.wordpress.com/2007/08/25/a-beginner%E2%80%99s-guide-to-calling-a-net-library-from-access/
i translated his simple C# example into cobra:
- Code: Select all
namespace DotNetLibrary
class DotNetClass
def dotNetMethod(input as String) as String
return "Hello " + input
i ignored his section about using VS to automagically register the resulting assembly, figuring that MD almost certainly would not have anything equivalent, and instead went to the "Deployment" section to learn how to do it manually with regasm.
i didn't use a "strong name" for my cobra assembly. it's simply named "cobraexceltest.dll". arbitrarily, i put it on the desktop, figuring that i'd sort out any path issues with excel later on.
then, after regasm complained that it couldn't find cobra.core.dll, i put cobra.core.dll on the desktop as well. (i didn't really understand why regasm couldn't find cobra.core.dll, since it's already "registered".)
then, regasm made a new complaint, as follows (from the Win SDK command prompt):
C:\Windows\system32>gacutil /l cobraexceltest
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
The Global Assembly Cache contains the following assemblies:
Number of items = 0
C:\Windows\system32>gacutil /l cobraexceltest.dll
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
The Global Assembly Cache contains the following assemblies:
Number of items = 0
C:\Windows\system32>regasm /codebase c:\users\paul\desktop\cobraexceltest.dll
Microsoft .NET Framework Assembly Registration Utility version 4.0.30319.17929
for Microsoft .NET Framework version 4.0.30319.17929
Copyright (C) Microsoft Corporation. All rights reserved.
RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can ca
use your assembly to interfere with other applications that may be installed on
the same computer. The /codebase switch is intended to be used only with signed
assemblies. Please give your assembly a strong name and re-register it.
RegAsm : error RA0000 : A BadImageFormatException has been thrown while parsing
the signature. This is likely due to lack of a generic context. Ensure genericTy
peArguments and genericMethodArguments are provided and contain enough context.
C:\Windows\system32>
the article did predict that regasm would warn me that it wants a strong name, but what confused me was the "lack of a generic context" error. i have a hunch, but not for any good reason, that this could be related to 64-bit versus 32-bit. but that's just a hunch.
any help on understanding what this means, and what to do about it, very welcome. thanks.