I have a program which uses an API from dinput.dll (Direct Input), I have monitored it and the result is this:
API Name: DirectInputCreateEx
Module Name: C:\Windows\system32\DINPUT.dll
And about another program which uses Direct Input:
API Name: DirectInputCreateA
Module Name: C:\Windows\system32\DINPUT.dll
This API will update this registry key:
HKEY_CURRENT_USER\System\CurrentControlSet\Control\MediaProperties\PrivateProperties\DirectInput
I want to know How can I use Delphi to write a code which ONLY call this API for DirectInput dll?
Any Help is really appreciated...
In order to call Direct Input you will need a Delphi translation of the header file. The best such translation, to my knowledge, is available from the Clootie graphics pages.
You need to use the DirectInput.pas header translation.
As for writing a program that does not show a Window, here's the simplest template:
program MyProgram;
begin
//write your program's code here
end.
You state in a comment that the only function you wish to call is DirectInputCreateEx. To call that function you need the following import declaration:
function DirectInputCreateEx(hinst: THandle; dwVersion: DWORD;
const riidltf: TGUID; out ppvOut; punkOuter: IUnknown): HResult;
stdcall; external 'dinput.dll';
Related
I am complete new to pascal.
I want to call my function in .dll file in free pascal and I get following error when I run the project:
The procedure entry point GetProcAddress could not be located in the dynamic link library HNLib.dll.
here is the code:
Program Test;
function GetProcAddress : Integer; cdecl; external 'HNLib.dll';
function GetProcAddress : Single; cdecl; external 'HNLib.dll';
procedure GetProcAddress( X : Single); cdecl; external 'HNLib.dll';
procedure GetProcAddress; cdecl; external 'HNLib.dll';
begin
GetProcAddress( 5.5 );
readln;
end.
.pas file and dll are in one directory.
Please Help ME!
GetProcAddress is not what you seem to think it is; it's purpose is to locate named procedures or functions in a DLL and return the address of that function so it can be called from your code. You have to first use LoadLibrary to load the dynamic link library (DLL) into memory, and then pass a handle to that DLL as the first parameter of GetProcAddress and the name of the function whose address you want as the second parameter. If the function can be found in the DLL, it's address is returned, and you can use that address to call the function.
(In addition, GetProcAddress is pretty Windows-specific, and the majority of functions in the WinAPI are stdcall and not cdecl. Unless you have documentation saying that the functions are using the cdecl calling convention, you should probably use stdcall.)
You would also need at least the Windows unit in your uses clause, since that's where GetProcAddress and LoadLibrary are declared.
See the WinAPI documentation on LoadLibrary and GetProcAddress for more information.
For a beginning programmer, you'll probably find it easier to use static linking of the functions instead of dynamic (which you get with GetProcAddress). An example of static linking would be (untested !!!- just a quick code example, since I don't have 'HNLib.DLL' to link against):
// Your Dll import unit
unit MyDllProcs;
interface
function GetIntCalcResult(const IntVal: Integer);
implementation
function GetIntCalcResult(const IntVal: Integer); stdcall; external 'HNLib.dll';
end.
// Your own app's code
program Test;
interface
uses MyDllProcs;
implementation
function DoSomethingWithDll(const ValueToCalc: Integer): Integer;
begin
Result := GetIntCalcResult(ValueToCalc);
end;
begin
WriteLn('DoSomethingWithDll returned ', DoSomethingWithDll(10));
ReadLn;
end.
Note that when statically linking DLL functions like this, your DLL must be available when your app starts, and the function must be contained in that DLL; if not, your application won't load.
Also, note that you can't typically have multiple functions with the same name in the DLL, as there's no information available to use to figure which one to load when the load is being done. Each should have a separate, distinct name or the loading will probably fail.
I would like to build a custom setup, with an aero form, but I don't know how to start it.
Is there any way to use DWM API with inno setup?
function dwm(Wnd: HWnd; cxLeftWidth, cxRightWidth, cyTopHeight, cyBottomHeight: integer ): Longint; external 'DwmExtendFrameIntoClientArea#dwmapi.dll stdcall';
DWM API is a native API so you can access it using the DLL Import method.
Then you can call API functions in your script code.
But I would recommend against doing this. Since the DWM only works on Vista or later and it can be disabled by stopping the NT Service. It could prevent your installation from working on a machine that it was designed to work on.
Now that you posted your code...
Original declaration of the API you posted.
HRESULT WINAPI DwmExtendFrameIntoClientArea(
HWND hWnd,
__in const MARGINS *pMarInset
);
My best guess is that it should look like this instead.
type
Margins = record
cxLeftWidth : Integer;
cxRightWidth: Integer;
cyTopHeight: Integer;
cyBottomHeight: Integer;
end;
function DwmExtendFrameIntoClientArea(Wnd: HWnd;
var pMarInset : MARGINS) :
HRESULT;
external 'DwmExtendFrameIntoClientArea#dwmapi.dll cdecl';
you can use the third party tool ISSkin for inno setup
http://isskin.codejock.com/
hope this helps
I would not use such an approach in a setup program, but if you you really need it I would develop it in Delphi, wrap it in a DLL with a simpler API, and call that DLL from InnoSetup.
I'm building a Delphi Win32 app that should consume a Soap Service, which turns out to be a .NET based app. One function returns a DataTable. Of course, Delphi Win32 (not Delphi .NET) has no way of understanding this natively.
Any way I can make it work? I'll be happy to parse the XML manually too, but I've no idea how to get hold of the raw XML response.
The WSDL: https://stratus.voxamvia.co.za/api.asmx?WSDL
The function: GetNotifications which returns GetNotificationsResult, which builds as:
GetNotificationsResult = class(TRemotable)
private
Fnamespace: WideString;
Fnamespace_Specified: boolean;
FtableTypeName: WideString;
FtableTypeName_Specified: boolean;
procedure Setnamespace(Index: Integer; const AWideString: WideString);
function namespace_Specified(Index: Integer): boolean;
procedure SettableTypeName(Index: Integer; const AWideString: WideString);
function tableTypeName_Specified(Index: Integer): boolean;
published
property namespace: WideString Index (IS_ATTR or IS_OPTN) read Fnamespace write Setnamespace stored namespace_Specified;
property tableTypeName: WideString Index (IS_ATTR or IS_OPTN) read FtableTypeName write SettableTypeName stored tableTypeName_Specified;
end;
Any help appreciated!
Would it help if I implement RemObjects?
You can build your dataset from xml. This should give you a starting point: http://www.gekko-software.nl/DotNet/Art07.htm and http://www.gekko-software.nl/DotNet/Art08.htm.
I haven't used DataAbstract from RemObjects, so I can not give an advice on it.
LE: you can access and consume a web service written in .net by following this simple article well written by drbob - Consuming C# Web Services with Delphi 7 Professional
which contains also a small example on how to build dynamically and how to use the THttpRio (is the same as the Mikael Eriksson's answer)
Any way I can make it work? I'll be happy to parse the XML manually
too, but I've no idea how to get hold of the raw XML response.
You can get it in the OnAfterExecuteEvent on your THTTPRIO component. There you will have SOAPResponse: TStream as a parameter.
Update:
To get the event to fire you add a THTTPRIO component, create the event handler and use the RIO component as the third parameter to GetAPISoap.
This worked for me. HTTPRIO1 is a component on the form.
procedure TForm7.Button1Click(Sender: TObject);
var
A: APISoap;
begin
A := GetAPISoap(False, '', HTTPRIO1);
A.Validate_User('', '');
end;
I need to initiate a call using TAPI from Delphi 2006. I'd like it to be as simple as possible. Any suggestions for a simple component? Is it in JEDI?
you can use the TurboPower Async Professional, some time ago I used this library and worked perfect, you can find more info about tapi and the AsyncPro component in this link.
Here is a list of components some freeware some shareware
http://www.torry.net/pages.php?id=199
Thanks
To use Tapi and delphi all you need is 2 things.
a. import the dll and create the tlb file.
in the delphi menu, go to componenets, then choose import components, then choose import type library, type "tapi3" and pick the tapi3.dll.
b. with the dll created to make a call you simple need to use
procedure TForm1.Button1Click(Sender: TObject);
var
Request:ITRequest;
dispatch:ITDispatchMapper;
begin
Request := CoRequestMakeCall.create;
Request.MakeCall('555-5555','Tag','client name','Comment');
end;
and replace the '555-5555' with the user input file number, as string.
Add this line before the implementation
function tapiRequestMakeCallW(DestAddress: PWideChar; AppName: PWideChar;
CalledParty: PWideChar; Comment: PWideChar): LongInt; stdcall;
external 'TAPI32.DLL';
after that call tapiRequestMakeCallw like that
TapiSonuc:=tapiRequestMakeCallw(Phone,'', comment, Comment);
I have embedded a form in a DLL and can call the DLL and show the form and return various functions from the DLL back to the main app, however I cannot figure out how to get the DLL to trigger events in the main applications form.
For example in the main app I have a dataset and I want to have a button on the form in the DLL to goto a certain record in the dataset but cannot see how this is done.
Can anybody could point me to an example or give me some pointers on how to to this?
If a DLL needs to invoke behavior in the host application, then the host should provide a callback function to the DLL that the DLL stores and calls when appropriate.
Your DLL exports a function that tells it to display the form, right? Add a couple of parameters to that function for the EXE to provide a pointer to a callback function. The callback function should accept at least one parameter, which should be of type Pointer. The caller (the EXE) will use that parameter as a context parameter, some way for it to be reminded why the DLL is calling the EXE's function. Your DLL will store the function pointer and the context pointer, and when it's time for the DLL to tell the EXE something, it will call that function and pass the context value back. The DLL won't do anything with the context value; it's just something to store and pass back to the EXE verbatim.
The DLL's interface will look like this:
type
TDllCallback = function(Context: Pointer): DWord; stdcall;
function DisplayForm(Parent: HWnd; Callback: TDllCallback; Context: Pointer): DWord; stdcall; external Dll;
The EXE will define a callback function like this:
function CallbackFunction(Context: Pointer): DWord; stdcall;
begin
TMainForm(Context).DoSomething;
Result := 0;
end;
It will call the DLL function like this:
procedure TMainForm.DoDllTaskClick(Sender: TObject);
begin
DisplayForm(Handle, CallbackFunction, Pointer(Self));
end;
Notice how the signature of CallbackFunction matches the TDllcallback type defined earlier. Tey both use the stdcall calling convention, and they're both standalone functions, not methods. Avoid methods since method pointers are particular to Delphi, and you shouldn't require your DLL to be used only by Delphi hosts, if possible.
Because DLL's code being executed in the same address space of main application there are a plenty ways of doing communications.
Define a callback function in the main app and give its address to the DLL.
Define a message handler in the main app and send a message from DLL in response to some event.
etc.