Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

UnmanagedFunctionPointer call generates an AccessViolation on vista

Posted on 2009-05-19
8
746 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 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