Architecture question on building a wrapper dll around another dll

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to wrap a DLL written in Cobol into a .net Dll. I am hoping of some
design guidance.

To call the Cobol DLL basically there 3 data areas that get passed into the
call.

Comm area (which contains the data returned from the call to the Cobol DLL)

Transaction area (which contains the data instructing the Cobol DLL of what
function to execute, login information, return code for success/failure).

Request area (which contains the parameter data Cobol DLL function needs).

All the areas are positional (and dynamic based on the function call) so
without a lot of work on the programers side it is difficult to make sure you
have everything set correctly so you get the required result. That is why I
am wrapping it. So other users can make a simple GetUserInfo(username) and
get a object back that contains the named members.

I have this working for some of the function. But am not sure I am designing
it correctly. I am looking at the patterns books and kind of think Facade or
Adapter. But not quite sure either of them are correct.

I expect I should have one place in the .net DLL that actually makes the
call to the DLL and in the separate functions (GetUserInfo(username)) set the
Transaction and request areas and pass them into the single call. My concern
is the comm area is pretty big (about 3000 bytes). And passing that around
may not be the best solution.

Any guidance is greatly appreciated!

Thanks,
Rich
 
Richard said:
Hi,

I need to wrap a DLL written in Cobol into a .net Dll. I am hoping of some
design guidance.

To call the Cobol DLL basically there 3 data areas that get passed into
the
call.

Comm area (which contains the data returned from the call to the Cobol
DLL)

Transaction area (which contains the data instructing the Cobol DLL of
what
function to execute, login information, return code for success/failure).

Request area (which contains the parameter data Cobol DLL function needs).

All the areas are positional (and dynamic based on the function call) so
without a lot of work on the programers side it is difficult to make sure
you
have everything set correctly so you get the required result. That is why
I
am wrapping it. So other users can make a simple GetUserInfo(username) and
get a object back that contains the named members.

I have this working for some of the function. But am not sure I am
designing
it correctly. I am looking at the patterns books and kind of think Facade
or
Adapter. But not quite sure either of them are correct.

I expect I should have one place in the .net DLL that actually makes the
call to the DLL and in the separate functions (GetUserInfo(username)) set
the
Transaction and request areas and pass them into the single call. My
concern
is the comm area is pretty big (about 3000 bytes). And passing that around
may not be the best solution.

I assume that the commarea is a byte array. Don't worry about "passing it
around" it's a reference type, and you are only passing a reference to it.


here's the right pattern:

public class UserInfo
{
string FirstName;
string LastName;
string Department;
}
public class CobolAdapter
{


public static string GetUserInfo(string UserName)
{
byte[] commArea = new byte[3000];
byte[] transactionArea = new byte[300];
byte[] requestArea = new byte[300];

//set appropriate data into buffers
CallCobolRoutine(commArea,transactionArea,requestArea);
bool success = false;
string errorMessage;
//marshal the return code into success
if (!success)
{
throw new RuntimeExeption("Cobol Routine Failed " + errorMessage);
}
UserInfo rv = new UserInfo();
//pull info from requestArea and marshal it into rv
return rv;

}


private static void CallCobolRoutine(byte[] CommArea, byte[]
TransactionArea, byte[] RequestArea)
{
//PInvoke COBOL .dll here
}
}


A possible optimization is to use a "Object Pool Pattern" to recycle the
buffers.

David
 
David,

Thanks! It is about the same I was was thinking. I think I get too hung up
on what the patterns should be.

I will look into then "Object pool pattern".

Thanks again!

rich


Hello David Browne" davidbaxterbrowne no potted,
Hi,

I need to wrap a DLL written in Cobol into a .net Dll. I am hoping of
some design guidance.

To call the Cobol DLL basically there 3 data areas that get passed
into
the
call.
Comm area (which contains the data returned from the call to the
Cobol DLL)

Transaction area (which contains the data instructing the Cobol DLL
of
what
function to execute, login information, return code for
success/failure).
Request area (which contains the parameter data Cobol DLL function
needs).

All the areas are positional (and dynamic based on the function call)
so
without a lot of work on the programers side it is difficult to make
sure
you
have everything set correctly so you get the required result. That is
why
I
am wrapping it. So other users can make a simple
GetUserInfo(username) and
get a object back that contains the named members.
I have this working for some of the function. But am not sure I am
designing
it correctly. I am looking at the patterns books and kind of think
Facade
or
Adapter. But not quite sure either of them are correct.
I expect I should have one place in the .net DLL that actually makes
the
call to the DLL and in the separate functions (GetUserInfo(username))
set
the
Transaction and request areas and pass them into the single call. My
concern
is the comm area is pretty big (about 3000 bytes). And passing that
around
may not be the best solution.
I assume that the commarea is a byte array. Don't worry about
"passing it around" it's a reference type, and you are only passing a
reference to it.

here's the right pattern:

public class UserInfo
{
string FirstName;
string LastName;
string Department;
}
public class CobolAdapter
{
public static string GetUserInfo(string UserName)
{
byte[] commArea = new byte[3000];
byte[] transactionArea = new byte[300];
byte[] requestArea = new byte[300];
//set appropriate data into buffers
CallCobolRoutine(commArea,transactionArea,requestArea);
bool success = false;
string errorMessage;
//marshal the return code into success
if (!success)
{
throw new RuntimeExeption("Cobol Routine Failed " +
errorMessage);
}
UserInfo rv = new UserInfo();
//pull info from requestArea and marshal it into rv
return rv;
}

private static void CallCobolRoutine(byte[] CommArea, byte[]
TransactionArea, byte[] RequestArea)
{
//PInvoke COBOL .dll here
}
}
A possible optimization is to use a "Object Pool Pattern" to recycle
the buffers.

David
 
Back
Top