Solved

UnmanagedFunctionPointer call generates an AccessViolation on vista

Posted on 2009-05-19
8
742 Views
Last Modified: 2012-06-21
Hi, I have a problem of something that works perfectly on xp, but not on vista. This make me think it might be related to some vista security features that xp does not have, but I couldn't seem to be able to find any relevant info on the net.

I declare the delegate as follow:
private unsafe delegate WFuncList** fnInitializeModule(void* lpPtr2Table);

WFuncList being a struct:

[StructLayout(LayoutKind.Explicit, Size = 0x10)]
        private struct WFuncList
        {
            [FieldOffset(0x00)]
            public int fpGenerateKeys;
            [FieldOffset(0x04)]
            public int fpUnload;//0x04
            [FieldOffset(0x08)]
            public int fpHandler;
            [FieldOffset(0x0C)]
            public int fpTick;
        };

I call it as follow:

fnInitializeModule init = (fnInitializeModule)Marshal.GetDelegateForFunctionPointer(new IntPtr(pInit + module), typeof(fnInitializeModule));
WFuncList** ppWFuncList = init(ppFuncList);

The last line throws and access violation on vista, and works perfectly fine on XP. I came across a post on a forum with someone having a similar issue, they said that it was probably due to the external module trying to allocate data in a pointer that was passed from managed code, and generating an exception.

Anyone experienced similar behavior on vista and found  a solution?
0
Comment
Question by:MikeDotNet555
8 Comments
 
LVL 11

Expert Comment

by:Agarici
ID: 24424863
what version of .net framework are you using?
according to ms GetDelegateForFunctionPointer from .net 2.0 is only supported on: Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

see this link: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getdelegateforfunctionpointer(VS.80).aspx

if you use 3.5 however they say it is supported on vista. see: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getdelegateforfunctionpointer.aspx

hth,
A.
0
 
LVL 3

Author Comment

by:MikeDotNet555
ID: 24425304
I do use 3.5, so this shouldn't be an issue, right?
0
 
LVL 4

Expert Comment

by:somnatic
ID: 24426144
Maybe a 64bit related issue?`
Could it be that int is being used as a 64bit type`?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 9

Accepted Solution

by:
tculler earned 500 total points
ID: 24426521
I have found COUNTLESS security things like this with Vista. It's because of Microsoft's "knee-jerk reaction" (as my friend puts it) to insecurities. Honestly, Vista is a nightmare--don't even worry about it, if you know what's good for you. I hate to answer a question with an answer such as this, but I fear that there really is no efficient solution to it. Don't get me wrong; I love Microsoft. My dad works there, and I hope/plan to work there someday myself, but Vista was a fluke, in a bad way. I suggest waiting, and moving on when Windows 7 comes out.

If you are REALLY determined to make this work on Vista, I sgugest you do it in C++. I don't have nearly as many problems in C++ as I do with the C# on Vista.

Sorry for the downer response, it's the best I can give. Hope it helps, regardless though,
Nate
0
 
LVL 3

Author Comment

by:MikeDotNet555
ID: 24428561
@somnatic: I tough about this, but I do not have any vista32 to test at the moment. I also have similar problems on windows server 2003 32bit and I think some security of vista were also implemented on windows server. I think I will try to find a vista32 to test it out.

@tculler: Yes, that is probably what I do and run my apps on xp since it is not something that needs top be redistributable very much, the only problem is that nowadays it's almost impossible to buy new computers with xp and finding xp drivers is a real pain.
0
 
LVL 4

Expert Comment

by:somnatic
ID: 24457828
Hi Mike

Why not simply try something like:

[StructLayout(LayoutKind.Explicit, Size = 0x10)]
        private struct WFuncList
        {
            [FieldOffset(0x00)]
            public Int32 fpGenerateKeys;
            [FieldOffset(0x04)]
            public Int32 fpUnload;//0x04
            [FieldOffset(0x08)]
            public Int32 fpHandler;
            [FieldOffset(0x0C)]
            public Int32 fpTick;
        };

I'd say it's worth a try :)

Regards
Thomas
0
 
LVL 3

Author Comment

by:MikeDotNet555
ID: 24458808
Well I tested it (on vista32) and it is really a vista security issue. As it goes now, I don't think I will ever find a solution for it, so I guess I will stick to XP.

Thanks for reply everyone.
0
 
LVL 3

Author Closing Comment

by:MikeDotNet555
ID: 31583144
Well I guess I will stick to xp for now, I dont see any solution for this problem.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question