Solved

UnmanagedFunctionPointer call generates an AccessViolation on vista

Posted on 2009-05-19
8
735 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
Comment Utility
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
Comment Utility
I do use 3.5, so this shouldn't be an issue, right?
0
 
LVL 4

Expert Comment

by:somnatic
Comment Utility
Maybe a 64bit related issue?`
Could it be that int is being used as a 64bit type`?
0
 
LVL 9

Accepted Solution

by:
tculler earned 500 total points
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 3

Author Comment

by:MikeDotNet555
Comment Utility
@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
Comment Utility
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
Comment Utility
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
Comment Utility
Well I guess I will stick to xp for now, I dont see any solution for this problem.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now