/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/tools/GSDumpGUI/Library/GSDXWrapper.cs
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/tools/GSDumpGUI/Library/GSDXWrapper.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (10 years, 9 months ago) by william
File size: 3926 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Runtime.InteropServices;
5
6 namespace GSDumpGUI
7 {
8 public class GSDXWrapper
9 {
10 private delegate void GSReplay(IntPtr HWND, IntPtr HInstance, String File, Boolean Show);
11 private delegate void GSConfigure();
12 private delegate IntPtr PSEgetLibName();
13
14 private GSReplay gsReplay;
15 private GSConfigure gsConfigure;
16 private PSEgetLibName PsegetLibName;
17
18 private Boolean Loaded;
19
20 private String DLL;
21 private IntPtr DLLAddr;
22
23 static public Boolean IsValidGSDX(String DLL)
24 {
25 NativeMethods.SetErrorMode(0x8007);
26 Boolean Ris = true;
27 IntPtr hmod = NativeMethods.LoadLibrary(DLL);
28 if (hmod.ToInt64() > 0)
29 {
30 IntPtr funcaddrReplay = NativeMethods.GetProcAddress(hmod, "GSReplay");
31 IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PS2EgetLibName");
32 IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
33
34 NativeMethods.FreeLibrary(hmod);
35 if (!((funcaddrConfig.ToInt64() > 0) && (funcaddrLibName.ToInt64() > 0) && (funcaddrReplay.ToInt64() > 0)))
36 {
37 Int32 id = NativeMethods.GetLastError();
38 System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt", DLL + " failed to load. Error " + id);
39 Ris = false;
40 }
41 }
42 else
43 {
44 Int32 id = NativeMethods.GetLastError();
45 System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt", DLL + " failed to load. Error " + id + Environment.NewLine);
46 Ris = false;
47 }
48 NativeMethods.SetErrorMode(0x0000);
49 return Ris;
50 }
51
52 public void Load(String DLL)
53 {
54 this.DLL = DLL;
55 NativeMethods.SetErrorMode(0x8007);
56 if (!IsValidGSDX(DLL))
57 throw new Exception("Invalid GSDX DLL");
58
59 if (Loaded)
60 Unload();
61
62 Loaded = true;
63 IntPtr hmod = NativeMethods.LoadLibrary(DLL);
64 if (hmod.ToInt64() > 0)
65 {
66 IntPtr funcaddrReplay = NativeMethods.GetProcAddress(hmod, "GSReplay");
67 IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PS2EgetLibName");
68 IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
69
70 gsReplay = (GSReplay)Marshal.GetDelegateForFunctionPointer(funcaddrReplay, typeof(GSReplay));
71 gsConfigure = (GSConfigure)Marshal.GetDelegateForFunctionPointer(funcaddrConfig, typeof(GSConfigure));
72 PsegetLibName = (PSEgetLibName)Marshal.GetDelegateForFunctionPointer(funcaddrLibName, typeof(PSEgetLibName));
73 DLLAddr = hmod;
74 }
75 NativeMethods.SetErrorMode(0x0000);
76 }
77
78 public void Unload()
79 {
80 NativeMethods.FreeLibrary(DLLAddr);
81 Loaded = false;
82 }
83
84 public void GSConfig()
85 {
86 if (!Loaded)
87 throw new Exception("GSDX is not loaded");
88 gsConfigure.Invoke();
89 }
90
91 public void GSReplayDump(String DumpFilename)
92 {
93 if (!Loaded)
94 throw new Exception("GSDX is not loaded");
95 gsReplay.Invoke(new IntPtr(0), new IntPtr(0), DumpFilename, false);
96 }
97
98 public String PSEGetLibName()
99 {
100 if (!Loaded)
101 throw new Exception("GSDX is not loaded");
102 return Marshal.PtrToStringAnsi(PsegetLibName.Invoke());
103 }
104 }
105 }

  ViewVC Help
Powered by ViewVC 1.1.22