PC Review


Reply
Thread Tools Rate Thread

Access code having same name but different case from VB?

 
 
Benjamin Lukner
Guest
Posts: n/a
 
      17th Nov 2004
Hi!

I have a C# driver dll for a barcode scanner that exposes several
controls and classes. The problem is that the controls are written in
upper case and the classes in upper and lower case,
e.g. UPCEAN & UPCEan.

It's no problem to use the dll in C#, but VB always picks the control
and I have no access to the class. I tried to edit the code with a text
editor and compile it in the dev env. without opening the file, but it
didn't help.

Does anybody know a trick how to get access to the classes under VB?
The only thing I can imagine is writing a wrapper dll with different
names for the classes and controls in C# ...


Kind regards,

Benjamin Lukner
 
Reply With Quote
 
 
 
 
Daniel Moth
Guest
Posts: n/a
 
      17th Nov 2004
The option you describe (wrapper C# dll) is the only one that comes to mind
if you don't want/can't tamper with the existing one.

I suggest, next time you use a 3rd party C# dll ask them to mark it (e.g. in
the AssemblyInfo.cs) with:
[assembly: System.CLSCompliant(true)] //done by default in VB

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Benjamin Lukner" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Hi!
>
> I have a C# driver dll for a barcode scanner that exposes several controls
> and classes. The problem is that the controls are written in upper case
> and the classes in upper and lower case,
> e.g. UPCEAN & UPCEan.
>
> It's no problem to use the dll in C#, but VB always picks the control and
> I have no access to the class. I tried to edit the code with a text editor
> and compile it in the dev env. without opening the file, but it didn't
> help.
>
> Does anybody know a trick how to get access to the classes under VB?
> The only thing I can imagine is writing a wrapper dll with different names
> for the classes and controls in C# ...
>
>
> Kind regards,
>
> Benjamin Lukner



 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      17th Nov 2004
.... actually I should say that reflection would also work in this case but
unless you only need a couple of calls or you don't care about perf I would
go for the wrapper.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Daniel Moth" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The option you describe (wrapper C# dll) is the only one that comes to
> mind if you don't want/can't tamper with the existing one.
>
> I suggest, next time you use a 3rd party C# dll ask them to mark it (e.g.
> in the AssemblyInfo.cs) with:
> [assembly: System.CLSCompliant(true)] //done by default in VB
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
>
> "Benjamin Lukner" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
>> Hi!
>>
>> I have a C# driver dll for a barcode scanner that exposes several
>> controls and classes. The problem is that the controls are written in
>> upper case and the classes in upper and lower case,
>> e.g. UPCEAN & UPCEan.
>>
>> It's no problem to use the dll in C#, but VB always picks the control and
>> I have no access to the class. I tried to edit the code with a text
>> editor and compile it in the dev env. without opening the file, but it
>> didn't help.
>>
>> Does anybody know a trick how to get access to the classes under VB?
>> The only thing I can imagine is writing a wrapper dll with different
>> names for the classes and controls in C# ...
>>
>>
>> Kind regards,
>>
>> Benjamin Lukner

>
>



 
Reply With Quote
 
Benjamin Lukner
Guest
Posts: n/a
 
      17th Nov 2004
Daniel Moth wrote:
> .... actually I should say that reflection would also work in this case but
> unless you only need a couple of calls or you don't care about perf I would
> go for the wrapper.


Thanks for your fast reply!

Do you have some sample code by chance showing how to use reflection?
I tried to do, but I can only load the dll and show its file name


Kind regards,

Benjamin Lukner
 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      17th Nov 2004
You don't need to load the dll via reflection. Reference and use it as you
normally would. Use reflection only when you need to get past the case
sensitivity issue. E.g.

//'C# Server code
namespace Test{
public class SomeClass{
public void SomeMethod(){
System.Windows.Forms.MessageBox.Show("1","ine");
}
public void somemethod(){
System.Windows.Forms.MessageBox.Show("2","two");
}
}
}

'//VB Client code in some method
Dim o As New Test.SomeClass
Dim t As Type = o.GetType()
Dim mi As MethodInfo
mi = t.GetMethod("somemethod")
mi.Invoke(o, Nothing)
mi = t.GetMethod("SomeMethod")
mi.Invoke(o, Nothing)

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Benjamin Lukner" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Daniel Moth wrote:
>> .... actually I should say that reflection would also work in this case
>> but unless you only need a couple of calls or you don't care about perf I
>> would go for the wrapper.

>
> Thanks for your fast reply!
>
> Do you have some sample code by chance showing how to use reflection?
> I tried to do, but I can only load the dll and show its file name
>
>
> Kind regards,
>
> Benjamin Lukner



 
Reply With Quote
 
Benjamin Lukner
Guest
Posts: n/a
 
      17th Nov 2004
Hi!

I tried, but still have a problem...
The naming collision is between a control and a class.
I now can access the class, but I don't know how to access its properties:

Dim oSettings As xxx = New xxx

Dim t1 As Type = oSettings.GetType
Dim t As Type
Dim mis() As System.Reflection.MemberInfo
Dim mi As System.Reflection.MemberInfo
Dim pi As System.Reflection.PropertyInfo

mis = t1.GetMember("UPCEan")
mi = mis(0) ' Now I have access to my class

t = mi.GetType ' !! This is the code line that does not work
' !! because I get System.MemberInfo, of course

pi = t.GetProperty("EnableUPCA") ' Returns Nothing
pi.SetValue(pi, True, Nothing)


Is it possible to convert the MemberInfo to its original class or get
access to its members anyway?


Kind regards,

Benjamin Lukner
 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      17th Nov 2004
Sorry, not sure I understand the question. On properties, working with my
original example the following should work:

//'C# side
public string SomeProp{get{return "Hi";}}

'// VB side
Dim pi As PropertyInfo = t.GetProperty("SomeProp")
MessageBox.Show(pi.GetValue(o, Nothing))

Now, I feel I must reiterate my suggestion to go down the wrapper route.
Just a bunch of thin C# proxy objects will be easier to code against and
faster at runtime and easier to maintain for the future.

If you insist on the reflection path, I suggest you code against the library
as you normally would (not all of it has to compile) and then translate
that code using reflection one step at a time.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Benjamin Lukner" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Hi!
>
> I tried, but still have a problem...
> The naming collision is between a control and a class.
> I now can access the class, but I don't know how to access its properties:
>
> Dim oSettings As xxx = New xxx
>
> Dim t1 As Type = oSettings.GetType
> Dim t As Type
> Dim mis() As System.Reflection.MemberInfo
> Dim mi As System.Reflection.MemberInfo
> Dim pi As System.Reflection.PropertyInfo
>
> mis = t1.GetMember("UPCEan")
> mi = mis(0) ' Now I have access to my class
>
> t = mi.GetType ' !! This is the code line that does not work
> ' !! because I get System.MemberInfo, of course
>
> pi = t.GetProperty("EnableUPCA") ' Returns Nothing
> pi.SetValue(pi, True, Nothing)
>
>
> Is it possible to convert the MemberInfo to its original class or get
> access to its members anyway?
>
>
> Kind regards,
>
> Benjamin Lukner



 
Reply With Quote
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      17th Nov 2004
You don't want to use MemberInfo. You need the either MethodInfo or
PropertyInfo

Dim pi as PropertyInfo = oSettings.GetType().GetProperty("UPCEan")
Dim prop as Object = pi.GetValue(oSettings)
pi = prop.GetType().GetProperty("EnableUPCA")
Dim val as Boolean = pi.GetValue(prop, Nothing)
pi.SetValue(prop, Nothing, True)

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Benjamin Lukner" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Hi!
>
> I tried, but still have a problem...
> The naming collision is between a control and a class.
> I now can access the class, but I don't know how to access its properties:
>
> Dim oSettings As xxx = New xxx
>
> Dim t1 As Type = oSettings.GetType
> Dim t As Type
> Dim mis() As System.Reflection.MemberInfo
> Dim mi As System.Reflection.MemberInfo
> Dim pi As System.Reflection.PropertyInfo
>
> mis = t1.GetMember("UPCEan")
> mi = mis(0) ' Now I have access to my class
>
> t = mi.GetType ' !! This is the code line that does not work
> ' !! because I get System.MemberInfo, of course
>
> pi = t.GetProperty("EnableUPCA") ' Returns Nothing
> pi.SetValue(pi, True, Nothing)
>
>
> Is it possible to convert the MemberInfo to its original class or get
> access to its members anyway?
>
>
> Kind regards,
>
> Benjamin Lukner



 
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
does Access 2003 have a "proper" case? Upper case/then Lower skyking@rcn.com Microsoft Access Queries 1 19th Aug 2009 04:52 AM
Change text from lower case to upper case in Access 2007 Gloria Microsoft Access 1 30th Dec 2008 06:24 AM
Can't find short cut for changing case ... upper case .... lower case JERRY Microsoft Word New Users 7 23rd Aug 2007 05:29 PM
In Access 2003 VB code, control names resetting to upper case =?Utf-8?B?ZG9uYWxkZw==?= Microsoft Access VBA Modules 4 20th May 2006 08:30 AM
What is the best case for accessing managed code from unmanaged code? Bae,Hyun-jik Microsoft VC .NET 4 28th Jul 2005 02:37 PM


Features
 

Advertising
 

Newsgroups
 


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