MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Pages: 1

2600
Original Title
Reged: 06/14/04
Posts: 99
Send PM


.Net Question, How to reference a dll with different names
#100299 - 01/26/07 11:31 PM


I am using a library that wraps a "dll". On Windows the dll goes by one name, on other OS's it goes by another. Currently, there is a compile time #if that sets a const string to the dll name and another const variable. This results in distributing 2 copies of the library, one for Windows users and one for other OS's.

Does anyone have recommendations on how I could implement a way that initializes everything after determining the OS version at runtime?



Anonymous
Unregistered
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: 2600]
#100534 - 01/28/07 11:16 PM


> I am using a library that wraps a "dll". On Windows the dll goes by one name, on
> other OS's it goes by another. Currently, there is a compile time #if that sets a
> const string to the dll name and another const variable. This results in distributing
> 2 copies of the library, one for Windows users and one for other OS's.
>
> Does anyone have recommendations on how I could implement a way that initializes
> everything after determining the OS version at runtime?

I've used dllimports under windows & windows ce where this often happens. You create two functions with different names and specify an entry point ( because the entry point is often the same in the two dll's ). From then on you can either use an if check on every call as dot net is helpful and will only try to open the dll when the code actually is called, the alternative is to use a delegate ( though this only works if the two functions take identical pointers ).

I don't have any code to hand, but I can dig something out if you need it.

smf

Edited by smf (01/28/07 11:16 PM)



2600
Original Title
Reged: 06/14/04
Posts: 99
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: ]
#100611 - 01/29/07 07:32 PM


>
> I've used dllimports under windows & windows ce where this often happens. You create
> two functions with different names and specify an entry point ( because the entry
> point is often the same in the two dll's ). From then on you can either use an if
> check on every call as dot net is helpful and will only try to open the dll when the
> code actually is called, the alternative is to use a delegate ( though this only
> works if the two functions take identical pointers ).
>
> I don't have any code to hand, but I can dig something out if you need it.
>
> smf

Thanks for the help and reply. I think I get what you are saying in the first example,
but if you get a chance some example code would help me get it to click. Do you have any
standard you follow for naming the two functions?

I have no experience with and I'll have to check if I can use a delegate, but I've put it
on my list of things to read up on.



Anonymous
Unregistered
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: 2600]
#101183 - 02/03/07 10:08 AM


> Thanks for the help and reply. I think I get what you are saying in the first
> example,
> but if you get a chance some example code would help me get it to click.

I'll dig some out next week.

> Do you have
> any
> standard you follow for naming the two functions?

Normally I append CF to the end of the name of the compact framework version & DT to the end of the desktop one. The delegate or wrapper function gets the name of the function, so looking at it you think it's just C/C++.

> I have no experience with and I'll have to check if I can use a delegate, but I've
> put it
> on my list of things to read up on.

delegate's are the equivalent of function pointers from C. You call them in the same way as a function, but you can point it at whatever you want. I'll try to dig out a simple example. You can also now pass them to unmanaged dll's as callbacks/function pointers, you've always had the ability on the desktop but compact framework 1 didn't let you do it. I recently wrote a managed wrapper around stone street one's bluetopia bluetooth stack, which heavily relies on callbacks. That waa quite fun.

smf



kkd
MAME Fan
Reged: 02/14/07
Posts: 2
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: ]
#102550 - 02/14/07 07:25 PM


>
> delegate's are the equivalent of function pointers from C. You call them in the same
> way as a function, but you can point it at whatever you want. I'll try to dig out a
> simple example. You can also now pass them to unmanaged dll's as callbacks/function
> pointers, you've always had the ability on the desktop but compact framework 1 didn't
> let you do it. I recently wrote a managed wrapper around stone street one's bluetopia
> bluetooth stack, which heavily relies on callbacks. That waa quite fun.
>
> smf


Is your wrapper for Stonestreet one's Bluetopia available for others to use? I need to use Bluetopia for a Symbol MC70.
Could you give an example of using delegates to unmanaged dll''s as callbacks?

kkd



Anonymous
Unregistered
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: kkd]
#102566 - 02/14/07 09:42 PM


> Is your wrapper for Stonestreet one's Bluetopia available for others to use?

Not for free.

> Could you give an example of using delegates to unmanaged dll''s as callbacks?

I'm pretty sure microsoft document it quite well, you just create the dllimport with a Delegate parameter & then pass in one ( you should keep a reference to it or it could be garbage collected while the unmanaged code is running ). The main problem is going through all the marshalling.

smf



kkd
MAME Fan
Reged: 02/14/07
Posts: 2
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: ]
#102575 - 02/15/07 12:01 AM


> > Is your wrapper for Stonestreet one's Bluetopia available for others to use?
>
> Not for free.
>
> > Could you give an example of using delegates to unmanaged dll''s as callbacks?
>
> I'm pretty sure microsoft document it quite well, you just create the dllimport with
> a Delegate parameter & then pass in one ( you should keep a reference to it or it
> could be garbage collected while the unmanaged code is running ). The main problem is
> going through all the marshalling.
>
> smf

What would it cost?

kkd



Anonymous
Unregistered
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: kkd]
#102711 - 02/16/07 06:28 AM


This particular conversation can move to private messages.

smf



Anonymous
Unregistered
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: 2600]
#103928 - 02/28/07 05:22 PM


better late than never I guess...

here are some clues as to how to do what you want.


public delegate Int32 WSAStartupDelegate( UInt16 wVersionRequired, byte[] lpWSAData );
public static WSAStartupDelegate WSAStartup;

public class Win32
{
[DllImport( "ws2_32.dll" )]
public static extern Int32 WSAStartup( UInt16 wVersionRequired, byte[] lpWSAData );
}

public class WinCE
{
[DllImport( "ws2.dll" )]
public static extern Int32 WSAStartup( UInt16 wVersionRequired, byte[] lpWSAData );
}

then do either:

WSAStartup = WinCE.WSAStartup;

or

WSAStartup = Win32.WSAStartup;

depending on which one you want. Then do WSAStartup() and it will call the relevant code.


or you can just decide whether to call WinCE.WSAStartup() or Win32.WSAStartup() at runtime. I find it better to not polute the code, but it's up to you.


Without the classes, this is how to have the same function in different dll's.

[DllImport("coredll.dll", EntryPoint="PeekMessage", SetLastError=true)]
private static extern bool PeekMessageCE(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);

[DllImport("User32.dll", CharSet=CharSet.Auto, EntryPoint="PeekMessage")]
private static extern bool PeekMessageDT(out MSG msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);

You then call either PeekMessageCE or PeekMessageDT.


smf

Edited by smf (02/28/07 05:23 PM)



alpa
MAME Fan
Reged: 03/06/07
Posts: 1
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: 2600]
#104550 - 03/06/07 12:24 PM


Hey Twisty!!

Your Forum rocks!!

Edited by twisty (03/06/07 03:49 PM)



twistyAdministrator
Space Lord
Reged: 09/18/03
Posts: 15570
Send PM


Re: .Net Question, How to reference a dll with different names new [Re: alpa]
#104567 - 03/06/07 03:51 PM


Sorry, you aren't allowed to advertise such sites here.





Pages: 1

MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Pi 
0 registered and 4 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 4829