Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Heres an example:

 

Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" ( _
     ByRef Destination As Any, _
     ByRef Source As Any, _
     ByVal Length As Int32)

 

This is the declairation, but there arn't any "Any" in .Net, Object is closer, but it would be better to overload the function/sub to handle certain conditions.

 

I keep trying different ways of overloading, but I get errors about expecting the end of the procedure which isn't there because its an API declaration.

Posted

Well, that looks interesting

 

While that link does have some interesting ideas and sure is useful, the issue isn't CopyMemory.

 

There are more than a few windows API's that have a declaration "As Any". "As Any" was basically a varient to leave a variable open to anything from string, pictureboxes, integers and buffers.

 

In .Net, you can overload a function so that you have many different functions with the same name, but different parameters. If you're given a picturebox as a parameter, it looks for the CopyMemory using Picturebox as a parameter - if non is found an exception is thrown.

 

I'm sure you can use "As Object" as everything in .Net is an object, but thats supposed to be poor programming and in this particular case, copymemory is supposed to quickly copy units of memory, so speed should be of the essence.

 

I can "Jig" it right now only using one form of the function (from a back buffer to a picturebox), but I'd like to learn the proper way to overload an API call without it giving an error and expecting a "End Function" or "End Sub" at the end.

 

That link you gave me does look interesting, though at the moment it just overloaded my head and sent me running for caffine. I'll have to settle down with that and figure it out :P

  • *Experts*
Posted

Maybe this is what you're looking for...

<Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint:="RtlMoveMemory")> Public Shared Function CopyMemory(ByVal dest As String, ByVal source As String, ByVal length As Integer) As Integer
' Keep this empty
End Function

 

The DllImportAttribute is another way to call Windows APIs in

.NET apps, just make sure the method you're attributing is static

(Shared in VB.NET). Anyway, using this method (no pun intended)

you can then created overloaded versions of it with different

parameters.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

yeah, I'm pretty sure thats what I'm looking for... though the first part is something I'm not used to seeing:

 

"<Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint:="RtlMoveMemory")>"

 

Not used to brackets in my VB... I guess its universal .Net stuff :P

 

It looks like it works... And I can declare it over and over again with different arguements? Or do I still need to declair them all as Overload functions?

  • *Experts*
Posted

You can declare them as Overloads if you want, but the compiler

will figure it out itself if you don't. So yes, you can change the

parameters.

 

The <>'s (which are []'s in C#) represent an Attribute. Attributes

are special... attributes (for lack of a better word) which you can

add to the declaration of any class, method, etc. (assuming that

attribute supports it; you wouldn't obviously put a DllImportAttribute,

which imports a method from a DLL, on a class). [mshelp=ms-help://MS.MSDNQTR.2003FEB.1033/vbcn7/html/vaconAttributesOverview.htm]Read more here[/mshelp].

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...