Using the build option on VS to automaticly register the object for
COM.
Using regasm
Using tlbexp
I have then tried to reference this as an exteral global function in
powerbuilder.
here is the code I have used.
for the c# dll with com wrapper...
using System;
using System.Runtime.InteropServices;
namespace Tester
{
[Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _Numbers
{
[DispId(1)]
int GetDay();
[DispId(2)]
int GetMonth();
[DispId(3)]
int GetYear();
[DispId(4)]
int DayOfYear();
}
[Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Tester.Numbers")]
public class Numbers : _Numbers
{
public Numbers() { }
public int GetDay()
{
return (DateTime.Today.Day);
}
public int GetMonth()
{
return (DateTime.Today.Month);
}
public int GetYear()
{
return (DateTime.Today.Year);
}
public int DayOfYear()
{
return (DateTime.Now.DayOfYear);
}
}
}
when this is registered it has the following registry entrys
HKEY_CLASSES_ROOT\CLSID\{guid} (default) REG_SZ
Tester.Numbers
HKEY_CLASSES_ROOT\CLSID\Tester.Numbers (default)
REG_SZ {guid}
HKEY_LOCAL_MACHINE\Software\classes\Tester.Numbers\CLSID
(default) REG_SZ {guid}
HKEY_LOCAL_MACHINE\Software\classes\CLSID\{guid} (default)
REG_SZ Tester.Numbers
I have then tryed to call a function in this dll by declareing it as a
Global External function with this code
FUNCTION int GetDay() Library "Numbers.dll"
FUNCTION int GetDay() Library "Tester.Numbers"
I am really running out of ideas as to how to get the use of these
functions in a client/server powerbuilder application.
Anyone got any ideas how I can get this working?
Many thanks
http://pbdj.sys-con.com/node/258395
oleobject loo_numbers
loo_numbers = CREATE oleobject
loo_numbers.ConnectToNewObject ( "Tester.Numbers" )
etc.
Many thanks on pointing me in the right direction, I have got things
working now.
A little point that I would like to add for the benifit of anyone else
trying this is that I tryed to pass in string variables to a function
in the DLL i created and it was failing see the following code...
PowerScript call...
oleobject loo_smtp
loo_smtp = CREATE oleobject
li_rc = loo_smtp.ConnectToNewObject ( "DotNetSMTP.WBSendMail" )
lb_sent = loo_smtp.sendEmail(ls_smtp, ls_sender, ls_recipient,
ls_subject, ls_text)
Destroy loo_smtp
C# DLL....
public bool sendEmail(string smtp, string sender, string recipient,
string subject, string text)
{
SmtpClient smtpClient = new SmtpClient(smtp);
MailMessage mailMsg = new MailMessage();
MailAddress fromEmail = new MailAddress(sender);
MailAddress toEmail = new MailAddress(recipient);
mailMsg.Subject = subject;
mailMsg.From = fromEmail;
mailMsg.To.Add(toEmail);
mailMsg.Body = text;
smtpClient.Send(mailMsg);
return true;
}
This was failing, I then tryed passing in the args like this
lb_sent = loo_smtp.sendEmail("serverName", "sone...@ddress.co.uk",
"someon...@ddress.co.uk", "Testing", "This is a test")
and it then worked.
The problem was the way i was declaring the datatype in c#
Changing the declaration from this....
public bool sendEmail(string smtp, string sender, string recipient,
string subject, string text)
To this ....
public bool sendEmail(String smtp, String sender, String recipient,
String subject, String text)
made it all work fine when passing in string variables as argument. I
am really not sure what the diffrence between declaring something in
c# as a String or a string however there does seem to be some.
Hope this helps someone.
I have done a little research on this now and think that I have the
answer.
They are not 2 diffrent data types as such...
String is of type System.String, if you remove the useing System;
statement you would no longer be able to reference it by typing just
String but you would need to type System.String.
but because the type System.String is so often used the team at VS
have mapped it via the string statement. So you no longer need the
using System; statement to reference it.
It is the same with int Vs Int32 - Now I guess that the problem is
that unmanaged code can not resolve this mapping so needs the direct
reference to the System.System type.
if that makes sense.