How to convert external procedure to class

Posted by rbf on 20-Oct-2008 04:09

I have a library containing the following code:

&IF "" EQ "WIN32" &THEN

procedure GetPrivateProfileStringA external "kernel32.dll":

define input parameter lpszSection as memptr.

define input parameter lpszEntry as memptr.

define input parameter lpszDefault as memptr.

define input parameter lpszReturnBuffer as memptr.

define input parameter cbReturnBuffer as long.

define input parameter lpszFilename as memptr.

define return parameter returnValue as long.

end procedure.

&ENDIF

Is it possible to convert this code to a class or is this one of the cases where a procedure can't be beaten?

All Replies

Posted by Admin on 20-Oct-2008 04:29

An internal/external procedure in a class is not possible. Keeping it in a separate .p and calling it from a class is one option.

.NET offers native Registry access in the Microsoft.Win32 namespace. That's another option (my preference in 10.2a).

Posted by Simon de Kraa on 20-Oct-2008 05:06

Instead of this particular API maybe you can use GET-KEY-VALUE?

Posted by GregHiggins on 20-Oct-2008 07:28

And i think it's important that you keep this technique to yourself. I mean, why would we want an example of what you're talking about? It would only pollute the message space with lots of sample code which is of no use to anyone. Personally, you'll never find me putting working samples on the net for other developers to use and learn from. What a waste that would be.

Posted by rbf on 20-Oct-2008 07:50

Instead of this particular API maybe you can use

GET-KEY-VALUE?

Well the disadvantage of GET-KEY-VALUE is that it operates on the current environment. But that is beside the point here, I was just asking about the technique to use when using external procedures like this.

And Mike, yes I assume all of this functionality can in 10.2A be replaced by .NET code which would eliminate the question. Can you post some example code?

Meanwhile I have to cope on this in production in 10.1C so I cannot make this jump forward yet.

The other part of my question is about the OPSYS preprocessor. How could I handle that? DYNAMIC-NEW of a subclass based on OPSYS?

Posted by Admin on 20-Oct-2008 08:02

I see no need for a DYNAMIC-NEW. OPSYS is checked at compile time, so you may keed everything strong typed and access the class in the &ELSE.

If your code needs to be compatible with previous releases you might need to check for PROVERSION as well. That's usually ugly.

Attached is a Registry wrapper class. It uses some of my error handling framework, so please remove all that until it compiles.

It's a class with only static methods, so please use it like:

Registry:SetRegistryValue ("User","Software\Consultingwerk Ltd.\Dynamics4.NET~\LoginScreen", "Position", cPosition) .

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/Registry.cls:550:0]

Posted by Simon de Kraa on 20-Oct-2008 08:31

KB-P133258: Is it possible to define an EXTERNAL method in a class in OOABL?

Status: Unverified

GOAL:

Is it possible to define an EXTERNAL method in a class in OOABL?

GOAL:

How to call DLL functions from a class in OOABL

FACT(s) (Environment):

Windows 32 Intel

OpenEdge 10.1x

CAUSE:

Enhancement Request# 0000003788

FIX:

This enhancement has not been implemented in the product. There is

currently no way to do this from an ABL class file. This must be done

in an ABL procedure (.p, .w, .i) file.

Posted by Simon de Kraa on 20-Oct-2008 08:33

Thanks Mike. And where can I download the rest of Dynamics4.NET?

Posted by Admin on 20-Oct-2008 09:29

FWIW,

What I did was to create a class that defined all the constants and methods to correspond to each external procedure. In the constructor, the class persistently runs a .p which contains all of the external procedures. Each method calls it's associated external procedure in the persistent procedure.

From within any code where an external procedure call is needed, call the method in the class.

I wrote this before static methods and properties were available. I'll probably rewrite the class to use all static methods so I don't need to NEW it.

I can post a small example if anyone's interested.

JL

Posted by GregHiggins on 20-Oct-2008 10:18

That's how I would do it; what I'm curious to know is whether it is possible to replace the persistent procedures with .net calls to window services. I think that's what Mike was demonstrating with his Registry.cls. Instead of accessing the procedures via a class wrapper, access replacement services which accomplish the same results using classes inherent in Windows.

Posted by Admin on 20-Oct-2008 10:23

Ahh.

It would be nice to see an example of that. That's a little more involved than anything I've done so far.

This thread is closed