Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / C# - AccessViolationException

Author
Message
Xarshi
18
Years of Service
User Offline
Joined: 25th Dec 2005
Location: Ohio
Posted: 8th Feb 2008 02:08 Edited at: 8th Feb 2008 02:10
So I'm getting this exception when trying to import functions from a dll I made. This is what the error message says (while running in debug mode) :


This is really bothering me because I somewhat need this to work. So I'll post some code showing the weird thing. And yes, this is from the GDK, I have some use for what I'm doing, and no, I'm not trying to compete with DGDK.NET. But heres the code I'm using to export the functions from the C++ *.Dll ( MSVC++ 2008 express ) :


Now, that seems fine, judging off the articles I've read about importing unmanaged code into .NET.

Now, here is the .NET code I've been using to import this function:


Now, in the main loop ( I don't have a window created yet), I basically just loop C#. I have it so that the DarkGDK function is defined within the dll from c++. What I did for that is I made 3 functions : Initialize_db(), Loop_db(), and Unload_db(). These are called in sequential order in the DarkGDK() function declaration. I have it so you set these from C#. For that, I made a delegate called FunctionPointerDelegate(); Heres the code I used for that:


And here is the code that assigns the functions:


And the functions from myGame1.Initialize/Update/Unload:



Heres the DarkGDK function declaration from the c++ dll:


Now, will I have to run the DarkGDK function from C#? If so, I have tried that also, but I got the AccessViolationException with that as well. Heres the code I used for that:


It is exported like the other functions, extern "C" and __declspec(dllexport).

So, after my very unordered post, do any of you think you could help? Thanks in advance

WC Physics - PhysX wrapper for Dark GDK.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Feb 2008 11:53
Quote: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Im not a C# guy but in VB.NET I have seen this when dealing with external dll's, and on those occassions I was always able to trace back the problem to a type mismatch between what the dll expects/returns vs the type being used in .NET code to pass/receive the values. Maybe start there if you havent (I only read the beginning part of your post as I wont be much help anyway)

[href]mod2software[/href]
Xarshi
18
Years of Service
User Offline
Joined: 25th Dec 2005
Location: Ohio
Posted: 8th Feb 2008 21:21
Well, it seems that I have everything working correctly. But I realized my DarkGDK function is not running. So now I think I'll have to make my own window, set it into gdk, and then start running it. But I don't know the order in which to use the internal functions :\. I think I have to use dbBegin() then dbOverrideHWND(), and then in the loop call dbRender(). I can only assume dbBegin() calls the internal functions to set up gdk. I can only hope at least. When I get it so a window with gdk shows up, then I think I'll be on my way.

WC Physics - PhysX wrapper for Dark GDK.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Feb 2008 21:26
this may have become more of a dgdk question, rather than a generic programming question.

Let me know if you want this moved to the dgdk forum, and ill move it. Cant promise it will arrive there intact however.

let me know

[href]mod2software[/href]
Xarshi
18
Years of Service
User Offline
Joined: 25th Dec 2005
Location: Ohio
Posted: 8th Feb 2008 21:34
Hm... that may be a good idea. I suppose we can try that. There are parts I have questions about c#, and parts I have questions about DGDK. I half suspect dgdk is causing the trouble, but am not entirely sure. I know when I try the DllImport, thats when the exception comes up.

WC Physics - PhysX wrapper for Dark GDK.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Feb 2008 23:49
yeah
ill move it

cross fingers...

[href]mod2software[/href]
Xarshi
18
Years of Service
User Offline
Joined: 25th Dec 2005
Location: Ohio
Posted: 9th Feb 2008 00:29
Ok, seemed like it worked fine. Now, to anyone who reads this, this is the question in the spotlight at the moment. How do you start up DGDK with its internal commands, such as dbBegin(), dbEnd(), dbRender(), and dbInitWindow(DWORD dwType, DWORD dwWidth, DWORD dwHeight, DWORD dwDepth, HINSTANCE hInstance, LPSTR programName) ?

Thats really all I need to accomplish.

WC Physics - PhysX wrapper for Dark GDK.

Login to post a reply

Server time is: 2024-09-29 11:19:23
Your offset time is: 2024-09-29 11:19:23