UnmanagedFunctionPointer call generates an AccessViolation on vista

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?
LVL 3
MikeDotNet555Asked:
Who is Participating?
 
tcullerConnect With a Mentor Commented:
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
 
AgariciCommented:
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
 
MikeDotNet555Author Commented:
I do use 3.5, so this shouldn't be an issue, right?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
somnaticCommented:
Maybe a 64bit related issue?`
Could it be that int is being used as a 64bit type`?
0
 
MikeDotNet555Author Commented:
@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
 
somnaticCommented:
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
 
MikeDotNet555Author Commented:
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
 
MikeDotNet555Author Commented:
Well I guess I will stick to xp for now, I dont see any solution for this problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.