PC Review


Reply
Thread Tools Rate Thread

How to Access C DLLs from C#??

 
 
neeraj.krishna@gmail.com
Guest
Posts: n/a
 
      25th Jul 2006
Hi,
Is there anyone who has tried accessing C Dlls from C#? I got to know
that its Platform invocation Service, but did'nt get enough
documentation.
Can you give me some links to it?
Especially when a Struct is defined in C, how do I use it in C#. For
example, if there is a structure in C DDL(say cdll.dll) called struct
ListFields{}. How do use it in C# code??
Regards,
Neeraj Krishna

 
Reply With Quote
 
 
 
 
Michael C
Guest
Posts: n/a
 
      25th Jul 2006
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> Is there anyone who has tried accessing C Dlls from C#? I got to know
> that its Platform invocation Service, but did'nt get enough
> documentation.
> Can you give me some links to it?
> Especially when a Struct is defined in C, how do I use it in C#. For
> example, if there is a structure in C DDL(say cdll.dll) called struct
> ListFields{}. How do use it in C# code??
> Regards,
> Neeraj Krishna


Here's a simple example

[DllImport("user32")]
private static extern int GetWindowRect(int hwnd, ref RECT lpRect);

private class RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}

>



 
Reply With Quote
 
neeraj.krishna@gmail.com
Guest
Posts: n/a
 
      25th Jul 2006
Hi,
But my structure is defined in C.....That is
In C DLL i have:
typedef struct Rect {
int x,y;
} MYRECT

In C to use this we write:
MYRECT rect1;

But to use the same DLL in C# WHAT SHOULD I DO???
I don't want to write a class and redefine the elements in it

Please help me ???

>
> Here's a simple example
>
> [DllImport("user32")]
> private static extern int GetWindowRect(int hwnd, ref RECT lpRect);
>
> private class RECT
> {
> public int Left;
> public int Top;
> public int Right;
> public int Bottom;
> }
>
> >


 
Reply With Quote
 
Laura T
Guest
Posts: n/a
 
      25th Jul 2006
C# cannot use types defined in a C DLL. You must redefine them in your C#
program.
Otherwise, you COULD create a COM/.NET wrapper in the C DLL for the C types
but it's a quite a lot of work.

<(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed)...
> Hi,
> But my structure is defined in C.....That is
> In C DLL i have:
> typedef struct Rect {
> int x,y;
> } MYRECT
>
> In C to use this we write:
> MYRECT rect1;
>
> But to use the same DLL in C# WHAT SHOULD I DO???
> I don't want to write a class and redefine the elements in it
>
> Please help me ???
>
>>
>> Here's a simple example
>>
>> [DllImport("user32")]
>> private static extern int GetWindowRect(int hwnd, ref RECT lpRect);
>>
>> private class RECT
>> {
>> public int Left;
>> public int Top;
>> public int Right;
>> public int Bottom;
>> }
>>
>> >

>



 
Reply With Quote
 
simida
Guest
Posts: n/a
 
      25th Jul 2006
I think U can find some useful information for P/Invoke.
Good lack!

(E-Mail Removed) wrote:
> Hi,
> Is there anyone who has tried accessing C Dlls from C#? I got to know
> that its Platform invocation Service, but did'nt get enough
> documentation.
> Can you give me some links to it?
> Especially when a Struct is defined in C, how do I use it in C#. For
> example, if there is a structure in C DDL(say cdll.dll) called struct
> ListFields{}. How do use it in C# code??
> Regards,
> Neeraj Krishna


 
Reply With Quote
 
simida
Guest
Posts: n/a
 
      25th Jul 2006
I think U can find some useful information for P/Invoke.
Good lack!

http://www.pinvoke.net/

(E-Mail Removed) wrote:
> Hi,
> Is there anyone who has tried accessing C Dlls from C#? I got to know
> that its Platform invocation Service, but did'nt get enough
> documentation.
> Can you give me some links to it?
> Especially when a Struct is defined in C, how do I use it in C#. For
> example, if there is a structure in C DDL(say cdll.dll) called struct
> ListFields{}. How do use it in C# code??
> Regards,
> Neeraj Krishna


 
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
Access .NET dlls from unmanaged programs =?Utf-8?B?Sm9hY2hpbQ==?= Microsoft C# .NET 6 17th May 2007 12:00 PM
Registering DLLs - Unmanaged and Managed DLLs gopal Microsoft C# .NET 3 28th Aug 2006 04:32 PM
Shared DLLs from Compact Framework drag unneccessary DLLs =?Utf-8?B?R2FyeSBWYXJnYQ==?= Microsoft Dot NET 1 31st Jan 2005 01:17 PM
service access denied to DLLs HVE Microsoft VB .NET 1 1st Dec 2003 11:28 PM
have variable that all dlls used by C# program can access? Les Caudle Microsoft C# .NET 2 18th Sep 2003 07:17 PM


Features
 

Advertising
 

Newsgroups
 


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