dll create conflict

R

Ron

Hello,

I am trying to create a C# test dll to try out in an MS
Access mdb application. I open up a session of vs2003,
select C#/Class Library. Here is my code:

---------------------------------------------
using System;

public class firstDll
{
public static int myFirstDll()
{
int n = 5;
return n;
}
}
-----------------------------------------------

Before I build the dll I go to Project (called "testdll")
properties and select 'Register for Com Interop' = True.
Then I build the dll. Then I create a reference to the
testdll.tlb file in MS Access. But when I try to use the
dll it doesn't work. Here is how I invoke it in the
Access mdb

------------------------------------
Sub testOutDll()
Dim fd As testdll.firstDll
Set fd = New testdll.firstDll
Debug.Print fd.myFirstDll
End Sub
------------------------------------

I am able to see the intellisense dropdown for

Dim fd As testdll.firstDll
Set fd = New testdll.firstDll

But I don't get the intellisense dropdown for

fd.myFirstDll

The idea is that I would see "5" in the debug window. Can
anyone see what I am doing incorrectly here?

Thanks,
Ron
 
R

Ron

I removed the static in

public static int myFirstDll()
....

Now the dll seems to work, but even though I get the
dropdowns for

Dim fd As New testdll.firstDll

I don't get the dropdown for

fd.myFirstDll

Any suggestions appreciated how I can make the dropdowns
work for the property.
 
M

Mythran

Ron said:
I removed the static in

public static int myFirstDll()
...

Now the dll seems to work, but even though I get the
dropdowns for

Dim fd As New testdll.firstDll

I don't get the dropdown for

fd.myFirstDll

Any suggestions appreciated how I can make the dropdowns
work for the property.

Hrm, you wouldn't see a method for a static method of a library because it's
static. You would, however, see the method if you tried
testdll.firstDll.myFirstDll because you are accessing it like it's static
(which it is). Example:

public class MyClass
{
private string mMyString;

public static int GetMyInteger()
{
return 1234;
}

public string GetMyString()
{
return mMyString
}

public MyClass(string MyString)
{
mMyString = MyString;
}
}

Now you can use the following:

MsgBox MyClass.GetMyInteger

Dim obj As MyClass

Set obj = New MyClass("Hello World!")
MsgBox obj.GetMyString
Set obj = Nothing


Hope this helps...

Mythran
 
R

Ron

Thanks, yes. This is very helpful.


-----Original Message-----



Hrm, you wouldn't see a method for a static method of a library because it's
static. You would, however, see the method if you tried
testdll.firstDll.myFirstDll because you are accessing it like it's static
(which it is). Example:

public class MyClass
{
private string mMyString;

public static int GetMyInteger()
{
return 1234;
}

public string GetMyString()
{
return mMyString
}

public MyClass(string MyString)
{
mMyString = MyString;
}
}

Now you can use the following:

MsgBox MyClass.GetMyInteger

Dim obj As MyClass

Set obj = New MyClass("Hello World!")
MsgBox obj.GetMyString
Set obj = Nothing


Hope this helps...

Mythran


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top