Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

UnmanagedFunctionPointer call generates an AccessViolation on vista

Posted on 2009-05-19
8
Medium Priority
?
770 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
[X]
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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
tculler earned 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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