This is from your tutorial on calling a managed class from native code:
If is use COM onterop to call a managed class, I get error "(80070057): The parameter is incorrect" if the managed class does not define the passed parameters as type string; for example, if a PIC X(1) parameter is passed from native code and the managed class parameter is PIC X(1).
Sometimes I need to pass a number of parameters. Where can I find the rules for how to pass parameters from native to managed using COM interop?
#VisualCOBOLThe image from your tutorial didn't post, but the managed class code goes something like this:
method-id managedMethod.
local-storage section.
01 custRecord.
05 contact pic x(20).
05 company pic x(20).
05 phone pic x(15).
procedure division using mystring as string.
set custRecord to mystring
move "John Smith" to contact
set mystring to custRecord
goback.
end method.
This is from your tutorial on calling a managed class from native code:
If is use COM onterop to call a managed class, I get error "(80070057): The parameter is incorrect" if the managed class does not define the passed parameters as type string; for example, if a PIC X(1) parameter is passed from native code and the managed class parameter is PIC X(1).
Sometimes I need to pass a number of parameters. Where can I find the rules for how to pass parameters from native to managed using COM interop?
#VisualCOBOLHello Phil,
It looks like you skipped an important step, which is to set the managed project to be registered as a COM server.
Please follow the steps below:
- Make sure you open Visual COBOL as administrator
- Double-click on the Properties header under the managed class project in Solution Explorer
- select the COBOL tab
- click on Advanced under Additional directives
- check the Register for COM interop option
- click OK
- save the change
- build the solution
You should now be able to call the managed class from the native program.
Regards,
This is from your tutorial on calling a managed class from native code:
If is use COM onterop to call a managed class, I get error "(80070057): The parameter is incorrect" if the managed class does not define the passed parameters as type string; for example, if a PIC X(1) parameter is passed from native code and the managed class parameter is PIC X(1).
Sometimes I need to pass a number of parameters. Where can I find the rules for how to pass parameters from native to managed using COM interop?
#VisualCOBOLThe project was already registered for COM interop. Please see my original question. I'm looking for documentation which spells out exactly what data types can be passed as parameters from native code to a managed class. I know I can pass a a record if it is defined in the managed method as a string. I can also pass a PIC X(2) and receive it in managed as a string. How about integer and decimal numbers? I've never been able to find Micro Focus documentation on exactly what data types can be passed and how they should be defined in your native code and how they should be defined in the method you invoke in the managed class.
This is from your tutorial on calling a managed class from native code:
If is use COM onterop to call a managed class, I get error "(80070057): The parameter is incorrect" if the managed class does not define the passed parameters as type string; for example, if a PIC X(1) parameter is passed from native code and the managed class parameter is PIC X(1).
Sometimes I need to pass a number of parameters. Where can I find the rules for how to pass parameters from native to managed using COM interop?
#VisualCOBOLWhen you are calling a managed code application from native code you are using the COM library support which has been retained from the Net Express product. This documentation is supplied in Visual COBOL in the separate help file, nxrclr.chm, which is installed in the Help folder of your installation. The default location is %ProgramFiles(x86)%\\Micro Focus\\Visual COBOL for Visual Studio 2012\\Help.
It can also be found here
From the native support the run-time converts the appropriate data types into COM data types and then passes these to the COM interop layer of the managed program which converts them into managed types.
PIC X or group items are passed as BSTR's and are received as System.String in the managed code.
Numeric items are coerced into the appropriate type and are received as the same type.
The following is a simple example of passing some of these types:
native client program:
$set ooctrl( p)
*----------------------------------------------------------------*
* VCCOMClient *
* *
* This program will create an instance of the VCCOMServer class *
* and then call its methods. *
* *
* Before this can be done you must register the VCCOMServer class*
* for use with COM by using Visual Studio 2010 to open up the *
* solution C:\\VCCOMDemo\\VCCOMServer\\VCCOMServer\\VCCOMServer.sln *
* and then select Rebuild Solution from the Build menu. *
*----------------------------------------------------------------*
id division.
program-id. VCCOMClient.
class-control.
VCCOMServer is class "$OLE$VCCOMServer.VCCOMServer".
working-storage section.
01 anInstance object reference.
01 aString pic x(50) value spaces.
01 anInteger pic x(4) comp-5 value 0.
01 aFloat comp-2 value 0.
01 aGroup.
05 CustName pic x(20).
05 CustCompany pic x(20).
05 CustInteger pic x(4) comp-5.
05 CustDecimal pic s9(4)v99.
procedure division.
invoke VCCOMServer "new" returning anInstance
invoke anInstance "testVCstring" using aString
display aString
invoke anInstance "testVCint" using anInteger
display anInteger
invoke anInstance "testVCFloat" using aFloat
display aFloat
invoke anInstance "testVCGroup" using aGroup
display CustName
display CustCompany
display CustInteger
display CustDecimal
stop run.
managed COM server:
identification division.
interface-id. InterfaceDef as "IVCCOMServer".
environment division.
repository.
method-id. testVCstring public.
local-storage section.
procedure division using lnkString as string.
end method.
method-id testVCint public.
local-storage section.
procedure division using lnkInt as binary-long.
end method.
method-id testVCFloat public.
local-storage section.
procedure division using lnkFloat as float-long.
end method.
method-id testVCGroup public.
local-storage section.
procedure division using lnkString as string.
end method.
end interface InterfaceDef.
class-id VCCOMServer.VCCOMServer implements type IVCCOMServer.
working-storage section.
method-id testVCstring.
local-storage section.
procedure division using lnkString as string.
move "From method testVCstring" to lnkString
goback.
end method.
method-id testVCint public.
local-storage section.
procedure division using lnkInt as binary-long.
move 50 to lnkInt
goback.
end method.
method-id testVCFloat public.
local-storage section.
procedure division using lnkFloat as float-long.
move 123.75 to lnkFloat
goback.
end method.
method-id testVCGroup public.
local-storage section.
01 lnkGroup.
05 lnkName pic x(20).
05 lnkCompany pic x(20).
05 lnkInteger pic x(4) comp-5.
05 lnkDecimal pic s9(4)v99.
procedure division using lnkString as string.
move "Chris Glazier" to lnkName
move "Micro Focus" to lnkCompany
move 20 to lnkInteger
move -987.12 to lnkDecimal
set lnkString to lnkGroup
goback.
end method.
end class.
This is from your tutorial on calling a managed class from native code:
If is use COM onterop to call a managed class, I get error "(80070057): The parameter is incorrect" if the managed class does not define the passed parameters as type string; for example, if a PIC X(1) parameter is passed from native code and the managed class parameter is PIC X(1).
Sometimes I need to pass a number of parameters. Where can I find the rules for how to pass parameters from native to managed using COM interop?
#VisualCOBOLThanks a lot. This is what I needed.