We are a group of users of Blackbaud products and are not affiliated with Blackbaud. We'd love to have you join our community to help and be helped in getting the most from your Blackbaud software.
Register now to join us to get independant advice on your system, connect with 3rd party consultants to help you maximize your database and have a real alternative to the official Blackbaud website.
I am just starting my first foray into C# and thought what better way than to begin using it with the API!
I know that this applies to VB.NET too so I thought I would put the question out there. The knowledgebase article giving an example of how to use C# with the API says that if you want the login prompt then you should:
call the win32 OleInitialize api first.
as in the following:
Code:
REAPI oRE7 = new REAPI();
//initialize with amServermode to avoid
//splash screen and login prompt. If you want to use amStandalone
//mode with the login prompt then you must call the win32 OleInitialize api first.
oRE7.Init ("WRE11111","Supervisor","admin",50,"",AppMode.amServer);
Does anyone have any examples of doing this? I cannot find the correct namespace for calling this. It is needed as the COM graphical objects use a different threading model to .NET and this will prevent a serious crash from occurring.
Hi David,
I haven't done it, but I believe that is an API call you have to register first, like so:
C#
Code:
[DllImport("ole32.dll")]
static extern int OleInitialize(IntPtr pvReserved);
VB.Net
Code:
Public Declare Function OLEInitialize Lib "ole32" Alias "OleInitialize" ()
As Integer
Also, when you call REAPI.Init, you'll need to leave the name/password blank, as well as the DB number if you want them to pick the DB to log into. Finally, you'll need to change the AppMode to Stand Alone... no point in a log-in form popping up on some remote server somewhere. ;-)
Jeff
PS - Good for you for picking up C#... I need to start doing the same.
I tried the example using VB.NET and it failed. I got an error message on the OLEInitialize function. I rewrote the code so that it matched the C#'s declaration and it worked fine.
Code:
Module Module1
Public Declare Function OLEInitialize Lib "ole32" Alias "OleInitialize" (ByVal intp As IntPtr) As Integer
Sub Main()
OLEInitialize(Nothing)
Dim oREAPI As New REDotNetAPI.REAPI
Dim oConstit As REDotNetAPI.CRecord
oREAPI.Init("WRE11111", , , 50, , REDotNetAPI.AppMode.amStandalone)
oConstit = New REDotNetAPI.CRecord()
oConstit.Init(oREAPI.SessionContext)
oConstit.LoadByField(REDotNetAPI.bbRECORDUniqueFields.uf_Record_CONSTITUENT_ID, 3)
System.Console.Write(oConstit.Fields(REDotNetAPI.ERECORDSFields.RECORDS_fld_FULL_NAME))
oConstit.CloseDown()
oConstit = Nothing
End Sub
End Module
Note that this was written using a pre-7.80 version i.e. before RE included the interop assemblies so the namespace "REDotNetAPI" may be different on later versions.
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;
using Blackbaud.PIA.RE7.BBREAPI;
namespace MyProj
{
class MyProj
{
[DllImport("ole32.dll")]
static extern int OleInitialize(IntPtr pvReserved);
[STAThread]
static void Main(string[] args)
{
OleInitialize(IntPtr.Zero);
REAPI oRE7 = new REAPI();
//initialize with amServer mode to avoid
//splash screen and login prompt. If you want to use amStandalone
//mode with the login prompt then you must call the win32 OleInitialize api first.
oRE7.Init("WRE11111", string.Empty, string.Empty, 50, "", AppMode.amStandalone);