PC Review


Reply
Thread Tools Rate Thread

calling C# DLL from VBA

 
 
Paul
Guest
Posts: n/a
 
      4th Nov 2006
Dear all,

I am very new to microsoft programming world and would definitely need
help. I tried created a C++ DLL and I can call it from Excel VBA, and
it works well.

Now I am trying to create a C# DLL, I can compile the DLL but I can't
call it from my Excel VBA. Everytime when I invoke the VBA macro it
complains the entry point of the DLL is not found. Are there something
missing during my DLL compilation step??

I remember that I have to define the "functions to be exposed" in a DEF
files for the C++ Linker. Do I have to do something similar for C#?

Thanks a lot.

Paul

 
Reply With Quote
 
 
 
 
Dave Patrick
Guest
Posts: n/a
 
      4th Nov 2006
Seems strange you would ask a C# question here rather than
http://www.microsoft.com/communities...&lang=en&cr=US

I'd run depends.exe against the DLL to see what functions are exposed.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Paul" wrote:
| Dear all,
|
| I am very new to microsoft programming world and would definitely need
| help. I tried created a C++ DLL and I can call it from Excel VBA, and
| it works well.
|
| Now I am trying to create a C# DLL, I can compile the DLL but I can't
| call it from my Excel VBA. Everytime when I invoke the VBA macro it
| complains the entry point of the DLL is not found. Are there something
| missing during my DLL compilation step??
|
| I remember that I have to define the "functions to be exposed" in a DEF
| files for the C++ Linker. Do I have to do something similar for C#?
|
| Thanks a lot.
|
| Paul
|


 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      4th Nov 2006

Thanks. I believe that's not purely a C# problem, since I am not sure
whether I have done something wrong with my excel VBA code too...

I have created the C# component, my code is looking like this:

public class Class1 {
public Class1() {
}
public int TestMethod(int i, int j) {
return i + j;
}
}

and I compiled using Visual studio for C# 2005 (.NET 2.0) with the
"Register for COM interop" option and have the ComVisible(true)
assembly attribute set.

Then I have set the reference to "testdll.tlb" in my Excel VBA
environment.
And my VBA code here

Sub test()
Dim a As testdll.Class1
Set a = New testdll.Class1
End Sub


The problem is.. everytime when I run the macro it complains at the 2nd
line of my VBA code:

"File or assembly name testdll, or one of its dependencies, was not
found."


I spent a day but still unable to figure out which step I was
missing....

If anyone know the answer, please help~~~~

Thank you very much.

Paul


On Nov 5, 12:58 am, "Dave Patrick" <DSPatr...@nospam.gmail.com> wrote:
> Seems strange you would ask a C# question here rather thanhttp://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg...
>
> I'd run depends.exe against the DLL to see what functions are exposed.
>
> --
>
> Regards,
>
> Dave Patrick ....Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]http://www.microsoft.com/protect
>
> "Paul" wrote:| Dear all,
> |
> | I am very new to microsoft programming world and would definitely need
> | help. I tried created a C++ DLL and I can call it from Excel VBA, and
> | it works well.
> |
> | Now I am trying to create a C# DLL, I can compile the DLL but I can't
> | call it from my Excel VBA. Everytime when I invoke the VBA macro it
> | complains the entry point of the DLL is not found. Are there something
> | missing during my DLL compilation step??
> |
> | I remember that I have to define the "functions to be exposed" in a DEF
> | files for the C++ Linker. Do I have to do something similar for C#?
> |
> | Thanks a lot.
> |
> | Paul
> |


 
Reply With Quote
 
Dave Patrick
Guest
Posts: n/a
 
      4th Nov 2006
That's a different error than you originally posted. Still a question for
the C# group. Try depends.exe or possibly one of these may help.

http://www.google.com/search?hl=en&l...23&btnG=Search

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Paul" wrote:
|
| Thanks. I believe that's not purely a C# problem, since I am not sure
| whether I have done something wrong with my excel VBA code too...
|
| I have created the C# component, my code is looking like this:
|
| public class Class1 {
| public Class1() {
| }
| public int TestMethod(int i, int j) {
| return i + j;
| }
| }
|
| and I compiled using Visual studio for C# 2005 (.NET 2.0) with the
| "Register for COM interop" option and have the ComVisible(true)
| assembly attribute set.
|
| Then I have set the reference to "testdll.tlb" in my Excel VBA
| environment.
| And my VBA code here
|
| Sub test()
| Dim a As testdll.Class1
| Set a = New testdll.Class1
| End Sub
|
|
| The problem is.. everytime when I run the macro it complains at the 2nd
| line of my VBA code:
|
| "File or assembly name testdll, or one of its dependencies, was not
| found."
|
|
| I spent a day but still unable to figure out which step I was
| missing....
|
| If anyone know the answer, please help~~~~
|
| Thank you very much.
|
| Paul


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling SQL from code has different behaviour than calling it from MS SQL Server Management Studio jeeji Microsoft C# .NET 1 29th Jun 2006 10:43 AM
Calling DoCmd.RunCommand acCmdSaveRecord, after calling an API function Savvoulidis Iordanis Microsoft Access Form Coding 2 19th Mar 2005 06:34 PM
Fail to send fax when making international fax calling / calling c =?Utf-8?B?c2Ftd2lzZQ==?= Windows XP Help 1 28th Dec 2004 02:31 PM
Calling FormsAuthentication.SignOut() after calling Response.Flush =?Utf-8?B?TWFydGluIExlZQ==?= Microsoft ASP .NET 1 28th Sep 2004 01:47 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier Microsoft ASP .NET 4 29th Jul 2004 02:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:12 PM.