473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Import Structure from unmanaged DLL (not function!)

Hi,

There is a constant structure with predefined fields values located in WinScard.dll. I am trying to get access to this structure
values in my C# code. Is there any way I can do that?

Basically I just need to obtain a memory reference like IntPtr to location of the structure in DLL, since I know the structure
layout.

I know that [DllImport()...] attribute works great for functions but looks like there is no instruction/attribute to associate
IntPtr and structure from an unmanaged DLL.

In my case I am trying to get access to
g_rgSCardT0Pci,
g_rgSCardT1Pci,
g_rgSCardRawPci
structures from WinScard.dll

Please help!

--
Regards,

Victor.
|||||||||||||||||||||||||||||||||||||||||||
"Be nice to the people you meet on the way up, because you'll be meeting the same people on the way down."
Jul 21 '05 #1
3 4129
Hmm ... the way I'd probably do that is to write my own unmanaged dll
to obtain the reference to that, then p/invoke that ...

Joel Martinez
http://www.onetug.org - Orlando .NET User Group
http://www.codecube.net - blog

Jul 21 '05 #2
Victor,

Try this:

[StructLayout(LayoutKing.Explicit, Size=#bytes)]
internal class SCardInfo (sic)
{
[FieldOffset(0)] public int g_rgSCardT0Pci;
[FieldOffset(4)] public int g_rgSCardT1Pci;
[FieldOffset(8)] public int g_rgSCardRawPci;
}

Basically, you tell .NET exactly how to marshal the structure. Then use
DllImport as you probably already are, roughly:

[DllImport("foo,dll", EntryPoint="MyFunc")]
static extern int GetCardInfo (SCardInfo cardInfo);

(Obviously, I don't know the names/signatures for the functions in your
DLL, but you get the idea.)

Finally, call the sucker:

SCardInfo temp = new SCardInfo();
int result = GetCardInfo(temp);

Good luck,

PC

"vk000" <vk******@hotmail.com> wrote in message
news:OX**************@TK2MSFTNGP10.phx.gbl...
Hi,

There is a constant structure with predefined fields values located in
WinScard.dll. I am trying to get access to this structure
values in my C# code. Is there any way I can do that?

Basically I just need to obtain a memory reference like IntPtr to location
of the structure in DLL, since I know the structure
layout.

I know that [DllImport()...] attribute works great for functions but looks
like there is no instruction/attribute to associate
IntPtr and structure from an unmanaged DLL.

In my case I am trying to get access to
g_rgSCardT0Pci,
g_rgSCardT1Pci,
g_rgSCardRawPci
structures from WinScard.dll

Please help!

--
Regards,

Victor.
|||||||||||||||||||||||||||||||||||||||||||
"Be nice to the people you meet on the way up, because you'll be meeting
the same people on the way down."

Jul 21 '05 #3
Is there any way I can do that?


I believe you can use GetProcAddress to get the pointers.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
0
by: Zoran Stipanicev | last post by:
Hi! I've declared structure in function and inside it template structure.It was all great untile i presed build. I'm using vc++ .net 2003 the error was something like: You can't declare template...
3
by: Panda2 | last post by:
Say I have a structure such as: struct Barn{ char type; int number; }animal so for example we might have data like animal.type cow animal.number 10
1
by: Tim | last post by:
Dear All, I have discovered, to my dismay, that the ShowDialog function will not function correctly when used with the AnimateWindow API. The owned form is opened behind the owning form on the...
0
by: josef | last post by:
Hello, how do I call the following unmanaged C function from C# float* Fx(int a, float* b1, float*b2, ...); thanks josef
0
by: MikeCS | last post by:
Hi all I would like some help with this issue. I am new to VB 2005 (OK with VB6) My problem is that I cannot seem to return a structure from a function. Example: I defined a structure in a...
1
by: sharadvasista | last post by:
I have a structure typedef struct t_abcd { int a; int b; int c; } abcd; I have to pass the structure to another function. I can do this in two ways.
24
by: karthikbalaguru | last post by:
Hi, I find that the structure padding is not being taken into account while using 'new' operator. Is there a way to enable it ? struct Dataunit { char dataid; int keyid;
2
by: Daugaard | last post by:
As the title says, I'm trying to put a function pointer in a structure at initialization time. The code below demonstrates this and also includes code for testing whether or not it works. It's fairly...
2
by: Sajini Biju | last post by:
Can I get a structure variable in function for eg:- struct stud{ char name}stud1; void student(char); void main() { char n; scanf("%s",n); strcpy(stud1.name,n);
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.