@CommonTater, timovjl,
many thanks for your input.
I've now a first working solution. The PB DLL function will be called () without parameter and delivers a dynamic string. For this scenario it seems, that it don't need even BSTR variables:
/
****************************************************************************
*
* File : main.c
*
* Purpose : based on Pelles C generic dialog based Win32
* application: test program for calling PB/Win32 DLLs
*
* copyright 2011 Dipl.-Ing. Volker Butzlaff
*
* 01/06/2011
*
*Pelles C v6.00.4 (calling PowerBasic Win32 v9.05 DLLs)
*
* ****************************************************************************/
#define WIN32_LEAN_AND_MEAN
#define WIN32_DEFAULT_LIBS
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include "main.h"
#include <wchar.h>
#include <objbase.h>
#include <assert.h>
#include <oleauto.h>
/** Prototypes **************************************************************/
static INT_PTR CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
typedef char* __stdcall LPFNCALLDLL( );
/** Global variables ********************************************************/
static HANDLE ghInstance;
/****************************************************************************
*
* Function: WinMain
*
* Purpose : Initialize the application. Register a window class,
* create and display the main window and enter the
* message loop.
*
****************************************************************************/
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
INITCOMMONCONTROLSEX icc;
WNDCLASSEX wcx;
ghInstance = hInstance;
/* TODO: set the ICC_???_CLASSES that you need. */
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES /*|ICC_COOL_CLASSES|ICC_DATE_CLASSES|ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES|... */;
InitCommonControlsEx(&icc);
/* Get system dialog information */
wcx.cbSize = sizeof(wcx);
if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
return 0;
/* Add our own stuff */
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
wcx.lpszClassName = _T("pbcallClass");
if (!RegisterClassEx(&wcx))
return 0;
/* The user interface is a modal dialog box */
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}
/****************************************************************************
*
* Function: MainDlgProc
*
* Purpose : Process messages for the Main dialog.
*
****************************************************************************/
char string1 [80];
char string2 [80];
char string3 [255];
HMODULE hLib;
LPFNCALLDLL* lpCallDll;
char *chReturn;
static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
/*
* TODO: Add code to initialize the dialog.
*/
return TRUE;
case WM_SIZE:
/*
* TODO: Add code to process resizing, when needed.
*/
return TRUE;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
/*
* TODO: Add more control ID's, when needed.
*/
case IDOK:
GetDlgItemText(hwndDlg, TB1, string1, 80);
/* GetDlgItemTextW(hwndDlg, TB2, string2, 1024000); */
/* alloc optional BSTR variable for later to implement outside DLL call */
/* BSTR expString = SysAllocString(string2); */
/* get handle to DLL */
hLib = LoadLibrary("pbdll.dll");
/* get pointer to DLL function */
lpCallDll = (LPFNCALLDLL*)GetProcAddress( hLib, "pbstring" );
/* get dynamic string from external DLL function */
chReturn = lpCallDll( );
/* concatinate the strings of the dialog fields and/or with the string from the external DLL */
strcpy(string3,string1);
strcat(string3, chReturn);
SetDlgItemText(hwndDlg, Label1, string3);
/* free BSTR variable */
/* SysFreeString(expString); */
/* release the DLL */
FreeLibrary(hLib);
return TRUE;
case IDCANCEL:
EndDialog(hwndDlg, TRUE);
return TRUE;
}
break;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
/*
* TODO: Add more messages, when needed.
*/
}
return FALSE;
}
For the next step I have to look at the samples again, because If I call the PB DLL function with a dynamic string as parameter, I think I need an explicit BSTR.
bye,
Volker