Jump to content


Photo

Gm .net Layer


  • Please log in to reply
70 replies to this topic

#1 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 31 July 2007 - 12:17 AM

Download link :)

The trick is simple. You tell my dll to load your dotnet dll. After that you let my dll make a new instance of a class in your dll. After that you can start executing functions. :) Simple.

To keep it simple there are only four functions: (what isn't included, you could make a own dotnet dll for)
layer_init() - Call once before using one of the other functions.
layer_loaddll (DLL NAME) - Returns the id of the loaded dotnet dll.
layer_createinstance (DLL HANDLE, NAMESPACE . NAME CLASS, ARGCOUNT, args...) - Returns the id of the created instance of the desired class. (Mostly you have no extra arguments.) The second argument must be in this form: "Namespace.Classname". The constructor will be executed if it exists with the given arguments (if any). You can create multiple instances of one class.
layer_function (INSTANCE HANDLE, FUNCTION NAME, RETURNTYPE [ty_real/ty_string],ARGCOUNT, args) - Executes the function that you desire. Overloads are supported.

The dll you make has the following requirements:
  • To receive/return numbers you need it to be a (System.)Double.
  • To receive/return strings you need it to be a (System.)String.
  • The functions used in the class and the class itself must be Public and must not be static.
  • Only 8 arguments are supported at the same time.
  • The type of the arguments is automatically detected.
I've added a sample in Visual Basic and C#, but writing in J#, C++ or any other language shouldn't be a problem. When distributing your game you have to include all dlls and the .manifest file that are in the zip, except the sample.dll is not required.

Download link :D

Edited by The_Cool_Gamer, 16 January 2008 - 02:54 PM.

  • 1

#2 TGMG

TGMG

    G-java creator

  • New Member
  • 706 posts
  • Version:GM8

Posted 31 July 2007 - 12:31 AM

Very useful, well done :)
  • 0

#3 the_doominator

the_doominator

    Eight Star

  • New Member
  • 925 posts

Posted 31 July 2007 - 03:17 PM

Very useful, well done :ph34r:

<{POST_SNAPBACK}>

Very cool!
  • 0

#4 oakwhiz

oakwhiz

    GMC Member

  • New Member
  • 268 posts

Posted 01 August 2007 - 01:40 AM

This is great! I can't test it yet though.
  • 0

#5 ATAX

ATAX

    GMC Member

  • New Member
  • 31 posts

Posted 03 August 2007 - 05:20 PM

Awesome!!
  • 0

#6 coolsmile

coolsmile

    Programmer

  • New Member
  • 1346 posts

Posted 03 August 2007 - 05:47 PM

I wonder if this would get the Giimote dll to work?
I'll try it :D
  • 0

#7 leif902

leif902

    GreenMan Games

  • New Member
  • 748 posts

Posted 03 August 2007 - 11:07 PM

I wonder if this would get the Giimote dll to work?
I'll try it :lol:

<{POST_SNAPBACK}>

It sure will ::lmao:: Thanks alot, this will definitly get me up and rolling. (No chance of getting the source is there? I'll give you credit. If you don't mind letting me see it feel free to email or PM me, if not don't worry about it)

- Leif
  • 0
Sam Whited (Leif902)
YoYo Games Wiki | SamWhited.com (blog)

#8 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 04 August 2007 - 12:44 AM

Pretty interesting, I used to think such a thing wasn't possible but it seems it is. Good work!
  • 0

#9 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 04 August 2007 - 03:22 PM

I rather keep the source code for the DLL myself. A lot of the handling of managed is done as in this example: http://www.codeguru....php/c4845/#more

Thanks for the other positive replies.
  • 0

#10 leif902

leif902

    GreenMan Games

  • New Member
  • 748 posts

Posted 04 August 2007 - 06:57 PM

I rather keep the source code for the DLL myself. A lot of the handling of managed is done as in this example: http://www.codeguru....php/c4845/#more

Thanks for the other positive replies.

<{POST_SNAPBACK}>


Alright thanks anyways, I hate doing all that native to managed wrapping crap, this DLL's gona make my life a whole lot easier.
- Leif
  • 0
Sam Whited (Leif902)
YoYo Games Wiki | SamWhited.com (blog)

#11 Danopia

Danopia

    Just another GMC member

  • GMC Member
  • 124 posts
  • Version:GM7

Posted 04 August 2007 - 07:52 PM

Yay! I can now complete my WeatherBugDLL! You have no idea how many people bugged me about it. :)
  • 0

#12 Rusky

Rusky

    GMC Member

  • GMC Member
  • 2492 posts
  • Version:Unknown

Posted 04 August 2007 - 08:11 PM

Very nice. This will be very useful.
  • 0

#13 cdm319

cdm319

    C++ Programmer

  • New Member
  • 885 posts

Posted 05 August 2007 - 09:32 PM

You've earned my respect for life... well... for the next hour or so anyway :huh:
  • 0

Chris Matthews, Co-Leader of Digital X

#14 Speewave123

Speewave123

    GMC Member

  • New Member
  • 67 posts

Posted 06 August 2007 - 12:55 AM

The Easiest way of GM Extending since C++ DLL Programming for GM\GML!
  • 0

#15 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 09 August 2007 - 08:59 AM

Yeah VB dls I can make. YOU ROCK
  • 0

#16 a2h

a2h

    GMC Member

  • New Member
  • 382 posts

Posted 11 August 2007 - 06:45 AM

# To receive/return numbers you need it to be a (System.)Double.
# To receive/return strings you need it to be a (System.)String.

Well then, that just killed my hopes of using this:
void __stdcall DetermineGrid2(/*    in   */ char* strMineBoard,
                              /*   out   */ float* probabilityMine,
                              /*   out   */ float* probabilityZeroMineAround,
                              /*   out   */ uint* numValidGen,
                              /*    in   */ uint numThread,
                              /*    in   */ uint minValidGen,
                              /*    in   */ uint timeCalculationMS)

  • 0

ion.developments does not exist, ignore my user title

#17 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 11 August 2007 - 11:15 AM

The function you give is an unmanaged (non-dotnet) function (with -maybe- some managed content). Only managed functions are supported.
  • 0

#18 a2h

a2h

    GMC Member

  • New Member
  • 382 posts

Posted 11 August 2007 - 11:30 AM

The function you give is an unmanaged (non-dotnet) function (with -maybe- some managed content). Only managed functions are supported.

What, that's a call to a non-.net DLL?
  • 0

ion.developments does not exist, ignore my user title

#19 Rusky

Rusky

    GMC Member

  • GMC Member
  • 2492 posts
  • Version:Unknown

Posted 11 August 2007 - 02:40 PM

also, game maker can only pass in/out doubles and strings anyway, so it didn't really 'kill' anything. it was already that way.
  • 0

#20 a2h

a2h

    GMC Member

  • New Member
  • 382 posts

Posted 13 August 2007 - 07:25 AM

also, game maker can only pass in/out doubles and strings anyway, so it didn't really 'kill' anything. it was already that way.

Many programming languages can convert values. If VB and VC# have the capability to change a value from one type to another (eg integer to double), well then...
  • 0

ion.developments does not exist, ignore my user title

#21 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 14 August 2007 - 11:08 AM

also, game maker can only pass in/out doubles and strings anyway, so it didn't really 'kill' anything. it was already that way.

Many programming languages can convert values. If VB and VC# have the capability to change a value from one type to another (eg integer to double), well then...

<{POST_SNAPBACK}>

Believe me when I say you MUST NOT asume so.
  • 0

#22 indYsoft

indYsoft

    GMC Member

  • New Member
  • 57 posts

Posted 14 August 2007 - 11:42 AM

why VB in gm just use VB not gm

gm= sloowww
vb= normal if u putt it in gm it will be slow as wel

...
  • 0

#23 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 14 August 2007 - 11:58 AM

That's a consideration the dll users should take, not the dll creator.
  • 0

#24 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 14 August 2007 - 02:00 PM

DLLs are designed to increase game speed, not decrease. However, this package has too many run-time files to make ita good solution, I'm thinking into going into C and C only.
  • 0

#25 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 14 August 2007 - 08:26 PM

Believe me when I say Java and .NET are the slowest things on Earth. A recent update to my Windows installation made explorer.exe into a .NET process. It is now 15% slowwer.
A recent editor which I found, made in Java and slightly better then programmer's notepad was as slow as the whole process in reseting my computer, circa 10 mins.
  • 0

#26 Rusky

Rusky

    GMC Member

  • GMC Member
  • 2492 posts
  • Version:Unknown

Posted 15 August 2007 - 11:45 PM

there are slower things than .NET.
  • 0

#27 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 16 August 2007 - 07:15 PM

Of course are .NET DLLs slower than other DLLs (if of course those DLLs are written properly), however writing a DLL in .NET could save a lot of time in developing since the .NET framework has a lot functions you can use straight away. However the speed of the .NET Framework is probably better than you might expect (extremely better in comparison with GML). Many applications don't require high performance, so they can write it in other languages that are quicker (such as GML or .NET).

A recent editor which I found, made in Java and slightly better then programmer's notepad was as slow as the whole process in reseting my computer, circa 10 mins.

That could just be bad bad programming or maybe it has a bug or something.

DLLs are designed to increase game speed, not decrease. However, this package has too many run-time files to make ita good solution, I'm thinking into going into C and C only.

This is not true. DLLs are there to add functionality.


Also one note about strings. In framework strings are handled as UTF, however in GM they are handled as ASCII, so the strings are converted by the DLL to ASCII.
  • 0

#28 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 17 August 2007 - 09:05 AM

Of course are .NET DLLs slower than other DLLs (if of course those DLLs are written properly), however writing a DLL in .NET could save a lot of time in developing since the .NET framework has a lot functions you can use straight away. However the speed of the .NET Framework is probably better than you might expect (extremely better in comparison with GML). Many applications don't require high performance, so they can write it in other languages that are quicker (such as GML or .NET).

A recent editor which I found, made in Java and slightly better then programmer's notepad was as slow as the whole process in reseting my computer, circa 10 mins.

That could just be bad bad programming or maybe it has a bug or something.

DLLs are designed to increase game speed, not decrease. However, this package has too many run-time files to make ita good solution, I'm thinking into going into C and C only.

This is not true. DLLs are there to add functionality.


Also one note about strings. In framework strings are handled as UTF, however in GM they are handled as ASCII, so the strings are converted by the DLL to ASCII.

<{POST_SNAPBACK}>

The editor was writen by some highly respected Java creators, I don't think it's a bug. GM isn't lightning fast, but on my pc it is faster then most Java projects I ever created, and these projects are the simplest ever created, even more considering I'm an early beginner in Java programming.
.NET does allow more functions, but don't forget that there are many other useless functions (at least for use with GM). Programming in lowwer level langauges gives better power then higher level ones (well most of them), as the higher ones are built using the lowwer ones. Because of Microsoft's "new" technologies, we are required to have ultra fast computers to run most of these technologies. Java was good as long as it remained a small, cross-platform, and powerfull language. But now that its much larger and "better", people may start to notice things are running too slow. I never had the best computers in my hands, but not the worst either. Because of the problems I named above, my PCs are behaving just like the worst/oldest computers. You might say upgrade, but I would reply, why? Next year and the others after that we will keep requiring better computers just to run poorly built and "New Technological" languages. Having a slow langauge and creating another language with it will produce an even slowwer one. This principle is not even thought about in programming.
  • 0

#29 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 17 August 2007 - 12:35 PM

Java or .NET are faster than GML (however they use somewhat more memory because of the framework).

Because of Microsoft's "new" technologies, we are required to have ultra fast computers to run most of these technologies.

You indeed need more computer power to run .NET applications, however the time to create such application is much shorter, which makes the (large) performance penalty affordable.

You can better look what you want to do and then pick the language. Want a very good performance, use C, ASM, C++, etc.. This is needed when you write something like a 3D DLL. However if you write a DLL to manipulate windows, connect to a server, write to a file, you don't need that very high performance. It is something you should consider when you make your program.
  • 0

#30 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 17 August 2007 - 02:21 PM

What I don't get is why this is happening. Framework or not, it is better to code everything yourself, plus everything achived with the framework is easily achived with the lowwer languages, as it is built with them. I guess you are right about the gml vs .NET/java, they're indeed slowwer because the use much more RAM.
In the end it does depend on what you need, but whenever I look at the local computer courses and programming requesits, they always ask for good knowledge of .NET or java. They wouldn't even know of better suited languages like delphi! For example a local web applications company builds anything it needs with .NET servers and more complicated technologies, meanwhile I could have easily used PHP.
Ah well babling here won't help it anyway. As of this dll, I think it's great for what it is and not for what it does.
  • 0

#31 Rusky

Rusky

    GMC Member

  • GMC Member
  • 2492 posts
  • Version:Unknown

Posted 17 August 2007 - 07:48 PM

Why does it matter? .NET isn't for making fast stuff.
  • 0

#32 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 18 August 2007 - 07:25 AM

Imagine building a new operating system with .NET, it would be reallly slow.
For some stupid reason, MS keeps making great but slow operating systems by using new technologies.
  • 0

#33 millzyman

millzyman

    GMC Member

  • GMC Member
  • 574 posts
  • Version:GM:Studio

Posted 18 August 2007 - 08:39 AM

Wow i will use this. I love using VB in dlls because i am very poorly skilled with C++ or delphi ect....
  • 0
Amigo Gamer (Link no longer available)
Amigo Gamer. New site for the development of Dusk and Dawn: Civilisations. Go there for updates about the game! Game is still being worked on.

#34 mrsmes

mrsmes

    GMC Member

  • GMC Member
  • 1506 posts
  • Version:GM:Studio

Posted 18 August 2007 - 10:48 AM

Download link :)

The trick is simple. You tell my dll to load your dotnet dll. After that you let my dll make a new instance of a class in your dll. After that you can start executing functions. ;) Simple.

To keep it simple there are only four functions: (what isn't included, you could make a own dotnet dll for)
layer_init() - Call once before using one of the other functions.
layer_loaddll (DLL NAME) - Returns the id of the loaded dotnet dll.
layer_createinstance (DLL HANDLE, NAMESPACE . NAME CLASS, ARGCOUNT, args...) - Returns the id of the created instance of the desired class. (Mostly you have no extra arguments.) The second argument must be in this form: "Namespace.Classname". The constructor will be executed if it exists with the given arguments (if any). You can create multiple instances of one class.
layer_function (INSTANCE HANDLE, FUNCTION NAME, RETURNTYPE [ty_real/ty_string],ARGCOUNT, args) - Executes the function that you desire. Overloads are supported.

The dll you make has the following requirements:

  • To receive/return numbers you need it to be a (System.)Double.
  • To receive/return strings you need it to be a (System.)String.
  • The functions used in the class and the class itself must be Public and must not be static.
  • Only 8 arguments are supported at the same time.
  • The type of the arguments is automatically detected.
I've added a sample in Visual Basic and C#, but writing in J#, C++ or any other language shouldn't be a problem. When distributing your game you have to include all dlls and the .manifest file that are in the zip, except the sample.dll is not required.

Download link :(

<{POST_SNAPBACK}>

mine will do the same except you can also do it in d&d format.
  • 0

Assuming I helped you out in a questions and answers topic won't you return the favour by helping me with one my coding problems, or recommend some one who can chat to me over pms about helping and how to overcome my obstacles, after all lets just say I did help you or them or many people with similar problems, in that topic.

Here i have a topic for those of you struggling with type writer text and mugshots in your games especially if it is a rpg see the link below for more info

http://gmc.yoyogames...howtopic=619103

almost no code needed, only uses two events.

click here for the l8est version of feed the alien pizza, it has some major polished up features.


#35 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 18 August 2007 - 04:22 PM

Imagine building a new operating system with .NET, it would be reallly slow.
For some stupid reason, MS keeps making great but slow operating systems by using new technologies.

<{POST_SNAPBACK}>

As stated before, you should consider which language you need to write your application. .NET has the advantage that it easy and secure (no bufferoverflows, etc.), however is much slower. Therefore it isn't useful for an OS, however for other applications it won't be a problem.
  • 0

#36 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 18 August 2007 - 05:29 PM

@ mrsmes - Yours could do nothing as it doesn't exist.
@ The_Cool_Gamer - Of course, but it remains that people must learn real languages, GM is good but everyone knows its slow, same with .NET.
Using .NET for your everyday life is bad, just as I said with Java. I used it for some projects were it couldn't be slow, being very small projects.
Personally, languages that use .NET aren't real languages. You'll all see, in a year or two will be seeing common controls .NET dlls for use with GM because most people doesn't even know how .NET works.
Of course MS wouldn't relate all the disadvantages of using .NET.
  • 0

#37 kubaszewczyk11

kubaszewczyk11

    GMC Member

  • New Member
  • 100 posts

Posted 31 December 2007 - 04:22 PM

Link to get GML:
box.net share
My mirror

:P
  • 0

#38 kubaszewczyk11

kubaszewczyk11

    GMC Member

  • New Member
  • 100 posts

Posted 31 December 2007 - 04:36 PM

Thank to fun lib for .net :P :) :P :P
  • 0

#39 Electronic_carz

Electronic_carz

    GMC Member

  • New Member
  • 36 posts

Posted 05 January 2008 - 06:47 PM

I Got an unexpected error while I was running the game

Any idea what might causes that?

Edited by Electronic_carz, 05 January 2008 - 07:00 PM.

  • 0

#40 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 05 January 2008 - 07:00 PM

I Got an unexpected error while I was running the game

Any idea that might causes that?

<{POST_SNAPBACK}>

Could you give somewhat more information about your problem. Unless you give more information, I cannot think of a solution.
  • 0

#41 Electronic_carz

Electronic_carz

    GMC Member

  • New Member
  • 36 posts

Posted 05 January 2008 - 07:11 PM

I downloaded the zip file including the c# and vb samples and other dll's
extracted it. double clicked on the .gmk started the sample by pressing on F5 and I ran into an error
  • 0

#42 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 05 January 2008 - 07:14 PM

I downloaded the zip file including the c# and vb samples and other dll's
extracted it. double clicked on the .gmk started the sample by pressing on F5 and I ran into an error

<{POST_SNAPBACK}>

What operating system are you using and do you have the .NET framework 2.0 installed?
  • 0

#43 Electronic_carz

Electronic_carz

    GMC Member

  • New Member
  • 36 posts

Posted 05 January 2008 - 07:27 PM

I have Windows XP Profesional and the .net framework 2.0 installed
  • 0

#44 AdM-Master

AdM-Master

    GMC Member

  • New Member
  • 1 posts

Posted 16 January 2008 - 02:48 PM

I would like to use this DLL, but the download-page is down. could you please upload it somewhere else?
  • 0

#45 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 16 January 2008 - 02:55 PM

I would like to use this DLL, but the download-page is down. could you please upload it somewhere else?

<{POST_SNAPBACK}>

I've changed the host of the file. You can get it from now on here: http://www.rocketsof...oads/gmdll2.zip
  • 0

#46 werewolf688

werewolf688

    Real Werewolf

  • New Member
  • 151 posts

Posted 18 January 2008 - 12:23 AM

Awesome, I didn't think it was posible, but hey!
  • 0

#47 DefuzionGames

DefuzionGames

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:Unknown

Posted 23 January 2008 - 03:36 PM

Imports System
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.Drawing.Imaging


Namespace ScreenShotDemo
    _
   '/ <summary>
   '/ Provides functions to capture the entire screen, or a particular window, and save it to a file.
   '/ </summary>
   Public Class ScreenCapture
      
      '/ <summary>
      '/ Creates an Image object containing a screen shot of the entire desktop
      '/ </summary>
      '/ <returns></returns>
      Public Function CaptureScreen() As Image
         Return CaptureWindow(User32.GetDesktopWindow())
      End Function 'CaptureScreen
      
      
      '/ <summary>
      '/ Creates an Image object containing a screen shot of a specific window
      '/ </summary>
      '/ <param name="handle">The handle to the window. (In windows forms, this is obtained by the Handle property)</param>
      '/ <returns></returns>
      Public Function CaptureWindow(handle As IntPtr) As Image
         ' get te hDC of the target window
         Dim hdcSrc As IntPtr = User32.GetWindowDC(handle)
         ' get the size
         Dim windowRect As New User32.RECT()
         User32.GetWindowRect(handle, windowRect)
         Dim width As Integer = windowRect.right - windowRect.left
         Dim height As Integer = windowRect.bottom - windowRect.top
         ' create a device context we can copy to
         Dim hdcDest As IntPtr = GDI32.CreateCompatibleDC(hdcSrc)
         ' create a bitmap we can copy it to,
         ' using GetDeviceCaps to get the width/height
         Dim hBitmap As IntPtr = GDI32.CreateCompatibleBitmap(hdcSrc, width, height)
         ' select the bitmap object
         Dim hOld As IntPtr = GDI32.SelectObject(hdcDest, hBitmap)
         ' bitblt over
         GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY)
         ' restore selection
         GDI32.SelectObject(hdcDest, hOld)
         ' clean up 
         GDI32.DeleteDC(hdcDest)
         User32.ReleaseDC(handle, hdcSrc)
         
         ' get a .NET image object for it
         Dim img As Image = Image.FromHbitmap(hBitmap)
         ' free up the Bitmap object
         GDI32.DeleteObject(hBitmap)
         
         Return img
      End Function 'CaptureWindow
      
      
      '/ <summary>
      '/ Captures a screen shot of a specific window, and saves it to a file
      '/ </summary>
      '/ <param name="handle"></param>
      '/ <param name="filename"></param>
      '/ <param name="format"></param>
      Public Sub CaptureWindowToFile(handle As IntPtr, filename As String, format As ImageFormat)
         Dim img As Image = CaptureWindow(handle)
         img.Save(filename, format)
      End Sub 'CaptureWindowToFile
      
      
      '/ <summary>
      '/ Captures a screen shot of the entire desktop, and saves it to a file
      '/ </summary>
      '/ <param name="filename"></param>
      '/ <param name="format"></param>
      Public Sub CaptureScreenToFile(filename As String, format As ImageFormat)
         Dim img As Image = CaptureScreen()
         img.Save(filename, format)
      End Sub 'CaptureScreenToFile
       _
      
      '/ <summary>
      '/ Helper class containing Gdi32 API functions
      '/ </summary>
      Private Class GDI32
         
         Public SRCCOPY As Integer = &HCC0020
          ' BitBlt dwRop parameter
         Public Shared<DllImport("gdi32.dll")>  _
         Function BitBlt(hObject As IntPtr, nXDest As Integer, nYDest As Integer, nWidth As Integer, nHeight As Integer, hObjectSource As IntPtr, nXSrc As Integer, nYSrc As Integer, dwRop As Integer) As Boolean
         
         Public Shared<DllImport("gdi32.dll")>  _
         Function CreateCompatibleBitmap(hDC As IntPtr, nWidth As Integer, nHeight As Integer) As IntPtr
         
         Public Shared<DllImport("gdi32.dll")>  _
         Function CreateCompatibleDC(hDC As IntPtr) As IntPtr
         
         Public Shared<DllImport("gdi32.dll")>  _
         Function DeleteDC(hDC As IntPtr) As Boolean
         
         Public Shared<DllImport("gdi32.dll")>  _
         Function DeleteObject(hObject As IntPtr) As Boolean
         
         Public Shared<DllImport("gdi32.dll")>  _
         Function SelectObject(hDC As IntPtr, hObject As IntPtr) As IntPtr
      End Class 'GDI32
       _
      
      '/ <summary>
      '/ Helper class containing User32 API functions
      '/ </summary>
      Private Class User32
         <StructLayout(LayoutKind.Sequential)>  _
         Public Structure RECT
            Public left As Integer
            Public top As Integer
            Public right As Integer
            Public bottom As Integer
         End Structure 'RECT
         
         
         Public Shared<DllImport("user32.dll")>  _
         Function GetDesktopWindow() As IntPtr
         
         Public Shared<DllImport("user32.dll")>  _
         Function GetWindowDC(hWnd As IntPtr) As IntPtr
         
         Public Shared<DllImport("user32.dll")>  _
         Function ReleaseDC(hWnd As IntPtr, hDC As IntPtr) As IntPtr
         
         Public Shared<DllImport("user32.dll")>  _
         Function GetWindowRect(hWnd As IntPtr, ByRef rect As RECT) As IntPtr
      End Class 'User32
   End Class 'ScreenCapture 
End Namespace 'ScreenShotDemo

So If I have this as a .vb file. I then compile it into a dll. Would I then be able to use this dll by using your dll.

If so what would be parameters I would need to use.

Fell free to use the code.
  • 0

#48 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 25 January 2008 - 10:58 PM

It won't work straight away. You need to adapt the code or write a wrapper class to comply with the rule "only Double and String output".

The modified source:
Imports SystemImports System.Runtime.InteropServicesImports System.DrawingImports System.Drawing.ImagingPublic Class ScreenCapture    Public Function CaptureScreen() As Image        Return CaptureWindow(User32.GetDesktopWindow())    End Function 'CaptureScreen    Public Function CaptureWindow(ByVal handle As IntPtr) As Image        Dim hdcSrc As IntPtr = User32.GetWindowDC(handle)        Dim windowRect As New User32.RECT()        User32.GetWindowRect(handle, windowRect)        Dim width As Integer = windowRect.right - windowRect.left        Dim height As Integer = windowRect.bottom - windowRect.top        Dim hdcDest As IntPtr = GDI32.CreateCompatibleDC(hdcSrc)        Dim hBitmap As IntPtr = GDI32.CreateCompatibleBitmap(hdcSrc, width, height)        Dim hOld As IntPtr = GDI32.SelectObject(hdcDest, hBitmap)        GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY)        GDI32.SelectObject(hdcDest, hOld)        GDI32.DeleteDC(hdcDest)        User32.ReleaseDC(handle, hdcSrc)        Dim img As Image = Image.FromHbitmap(hBitmap)        GDI32.DeleteObject(hBitmap)        Return img    End Function 'CaptureWindow    Public Sub CaptureWindowToFile(ByVal handle As IntPtr, ByVal filename As String, ByVal format As ImageFormat)        Dim img As Image = CaptureWindow(handle)        img.Save(filename, format)    End Sub 'CaptureWindowToFile    Public Sub CaptureScreenToFile(ByVal filename As String, ByVal format As ImageFormat)        Dim img As Image = CaptureScreen()        img.Save(filename, format)    End Sub 'CaptureScreenToFile    Private Class GDI32        Public Shared SRCCOPY As Integer = &HCC0020        <DllImport("gdi32.dll")> Public Shared Function BitBlt(ByVal hObject As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hObjectSource As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Integer) As Boolean        End Function        <DllImport("gdi32.dll")> _        Public Shared Function CreateCompatibleBitmap(ByVal hDC As IntPtr, ByVal nWidth As Integer, ByVal nHeight As Integer) As IntPtr        End Function        <DllImport("gdi32.dll")> Public Shared Function CreateCompatibleDC(ByVal hDC As IntPtr) As IntPtr        End Function        <DllImport("gdi32.dll")> Public Shared Function DeleteDC(ByVal hDC As IntPtr) As Boolean        End Function        <DllImport("gdi32.dll")> Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean        End Function        <DllImport("gdi32.dll")> Public Shared Function SelectObject(ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr        End Function    End Class 'GDI32    Private Class User32        <StructLayout(LayoutKind.Sequential)> _        Public Structure RECT            Public left As Integer            Public top As Integer            Public right As Integer            Public bottom As Integer        End Structure 'RECT        <DllImport("user32.dll")> Public Shared Function GetDesktopWindow() As IntPtr        End Function        <DllImport("user32.dll")> Public Shared Function GetWindowDC(ByVal hWnd As IntPtr) As IntPtr        End Function        <DllImport("user32.dll")> Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As IntPtr        End Function        <DllImport("user32.dll")> Public Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef rect As RECT) As IntPtr        End Function    End Class 'User32End Class 'ScreenCapturePublic Class GMWrapper    Private img As ScreenCapture = New ScreenCapture()    Public Function TakeFullscreen(ByVal filename As String) As Double        img.CaptureScreenToFile(filename, System.Drawing.Imaging.ImageFormat.Bmp)        Return 1    End Function    Public Function TakeWindow(ByVal windowhandle As Double, ByVal filename As String) As Double        img.CaptureWindowToFile(New IntPtr(CInt(windowhandle)), filename, System.Drawing.Imaging.ImageFormat.Bmp)        Return 1    End FunctionEnd Class
It had to modify it a bit to let it compile. I removed the namespace declaration, since VB gives the code already a namespace. Note the new wrapper class at the end of the code.

This is code you could use from Game Maker to use the dll:
layer_init();

testdll = layer_loaddll("Screenshotdemo.dll");

global.testclass = layer_createinstance(testdll,"ScreenShotDemo.GMWrapper",0);
if (global.testclass = 0)
{
    show_error("FAILED TO LOAD CLASS!",true);
}

layer_function(global.testclass,"TakeFullscreen",ty_real,1,"img1.bmp");
layer_function(global.testclass,"TakeWindow",ty_real,2,window_handle(),"img2.bmp");

  • 0

#49 millzyman

millzyman

    GMC Member

  • GMC Member
  • 574 posts
  • Version:GM:Studio

Posted 25 January 2008 - 11:47 PM

Ok so countinuing on from PM, of course i mis-spelt the name. So thats all good but i did get this error too

---------------------------
GM .Net Layer: Unhandled Exception
---------------------------
There has been an unhandled exception while finding the required function. Check the names and the argument types. This probably not error created by the "GM .Net Layer". The following trace is available:

System.MissingMethodException: Method 'System.Reflection.Assembly.Memory' not found.

   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

   at FuncReal(Double class_handle, SByte* funcname)

When seeking support, please contact the creater of the program and copy the complete error message. Press Ctrl+C to copy the message. Press Ok to continue or press Cancel to exit the application.
---------------------------
OK   Cancel   
---------------------------

This comesup 3 times
  • 0
Amigo Gamer (Link no longer available)
Amigo Gamer. New site for the development of Dusk and Dawn: Civilisations. Go there for updates about the game! Game is still being worked on.

#50 The_Cool_Gamer

The_Cool_Gamer

    Mister Cool Guy

  • New Member
  • 140 posts

Posted 25 January 2008 - 11:54 PM

Are you trying to call "System.Reflection.Assembly.Memory" directly from my DLL? You have to make a managed function yourself that uses that if you want to use it.

Could you post the GML you are using to call my dll?
  • 0