Punitha
3rd February 2010, 11:44
Hello,
Please let me know how I can invoke Baan with a specific bwc config from .NET using C#?
eg: In VB.NET, to invoke a specific BWC, the command CreateObject("Baan4.Application.someuser") can be used.
I would like to know how the same can be achieved using C#?
Thanks for your time and help.
goooch
3rd February 2010, 13:25
Hi Punitha,
I used something like this
object Baan = null ;
Type t;
t = Type.GetTypeFromProgID("Baan4.Application.someuser");
Baan = Activator.CreateInstance(t);
object[] Parameters = new Object[1];
Parameters[0] = 3600;
//Baan.Timeout = 3600;
Baan.GetType().InvokeMember("Timeout", BindingFlags.SetProperty, null, Baan, Parameters);
Parameters = new Object[2];
Parameters[0] = "otccomdll...";
Parameters[1] = "function.name...";
Baan.GetType().InvokeMember("ParseExecFunction", BindingFlags.InvokeMethod, null, Baan, Parameters);
...
//Baan.Quit();
Baan.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, Baan, null);
Punitha
3rd February 2010, 15:47
Dear Gooch,
Thanks much for your help. That really helps me a lot.
Out of curiosity, I noticed that Baan provides the following namespaces 'Baan4' and 'BWCLib'.
"Baan4Class" in "Baan4" provides the 'parseexecfunction', 'returnvalue' etc. methods,properties etc.
BWCLib provides the 'Configuration Class' etc.
Is there any way the above two can be utilised without using the 'Activator'?
Thanks again.
P.
goooch
3rd February 2010, 16:29
Dear Punitha
I prefer late binding. But MSVS and C# support two ways.
If you want I think you could create marshal object with .NET
Just import type library
And can you answer what's wrong with Activator?
I'm going to create some program for ASP.NET in some days
Best regards,
Goooch
Punitha
4th February 2010, 13:07
Dear Goooch,
Using 'activator' is fine. I was just trying to figure out the methods and props. provided by Baan and how to use them.
But, your response has helped me in my project.
Good luck to you in your future .NET projects.
P
emrispens
10th November 2010, 16:47
Dear Goooch,
I've used your code sample to connect with a custom made function in Baan. Now does this custom made function return a int value telling me if the actions where successfully executed or not, and if not, what wend wrong.
Calling this function, and sending my data works fine but I can't seem to get the return value. I was hoping you know how to do this and perhaps share some code to accomplish this?
Thank you very much.
Best regards,
Marijn
goooch
11th November 2010, 08:44
Hi Marijn,
try this
Int32 v = (Int32) Baan.GetType().InvokeMember("yourmethod"....
Best regards,
Goooch
emrispens
11th November 2010, 09:19
Hi Goooch
Thank you for a quick reply.
I've tried this already, I keep getting 0 or -1 back when i'm 100% sure of the fact that I should get 4 back (says something about trying to insert a key that already exists).
I think that this isn't possible but I would like to hear from people who've successfully created such a feature.
Thank again.
Best regards,
Marijn Rispens
goooch
11th November 2010, 09:54
Sorry
I've just tried this and it worked fine
Int32 v=(Int32)Baan.GetType().InvokeMember("ParseExecFunction", BindingFlags.InvokeMethod, null, Baan, Parameters);
String s = (String)Baan.GetType().InvokeMember("ReturnValue", BindingFlags.GetProperty, null, Baan, null);
The result of previous function's call (that was in Parameters Array) was in 's'.
The result of ParseExecFunction call was in 'v'
Best regards,
Goooch
emrispens
11th November 2010, 10:16
Hi Goooch
It works!! Thanks a lot!
Best regards,
Marijn
SandraDiehl
2nd September 2011, 18:37
I was checking out this posting while trying to figure out how I can work around having to remoted into 80+ PC to set up some new read only bw config files. The accounts will have predefined passwords that us admins will put in the config file and check the save password. We found in testing that when we push out the setup configure file it removes the stored password, so we can push out the configure file but still requires for us to remote onto the PC to setup the password.
So was thinking maybe I can write a c# console app that will start that predefined configuration file and some how pass the password when starting baan application, is there a way to pass the password and if so what is the syntax for the command?
constantino
16th August 2012, 17:51
Hey guys:
I noticed in the above posts that they're using a generic 'object' class type for the Baan automation class. That forces the programmer to use reflection to call the class' members. Instead, you cad add the 'BaanERP Type Library' reference to your C# project and then use the following code:
var baanobj = (IBwCOleAutomationServer)Activator.CreateInstance(Type.GetTypeFromProgID("Baan.Application.yourinstancehere"));
The object type for baanobj will be the IBwCOleAutomationServer interface. From here on you can call the object's members normally, like:
int x = baanobj.ParseExecFunction("ottstpapihand", "stpapi.stpapi.put.field(\"tfgld1101m000\",\"tfgld101.ttyp\",\"G01\")");
Makes everything easier.
baannoob
22nd January 2015, 01:43
I have a similar issue but I have to enter the login information in Baan dialog. I am not abl e to put the username and password in the .BWC file and automatically use that.
Is there a way to force our C# program to use a specific .BWC configuration file?
The code I have looks like this but it does seem to work
using Baan4;
connectBaan.Timeout = 36000;
connectBaan.ParseExecFunction("aBaanDllName", @"theBaanFunctionCall(""withOptParms"")");
Console.WriteLine(connectBaan.ReturnValue);
connectBaan.Quit();
Can you please help?
Thanks,
Baannoob
mark_h
22nd January 2015, 16:14
With the client today each bwc has its own connection on the automation tab. So I can have a prod.bwc with baan4.application.prod, then I can have a .bwc with baan4.application.prodauto. When I want to use automation I use the baan4.application.prodauto in the connection name.
Hope that helps - I only ever just played with this.