When using the following line code in Delphi 2010, a'm getting an "Access Violation" error, but the same code working fine in VC++.
The Delphi 2010 code is
var
hMyInf : HINF;
begin
hMyInf := SetupOpenInfFile('.\\DIGIMHID.INF','Mouse', INF_STYLE_WIN4,Nil);
The VC++ code is
hMyInf = SetupOpenInfFile(".\\DigimHID.inf", "Mouse", INF_STYLE_WIN4, NULL);
Please help me to solve this issue. Thanks All.
Call
LoadSetupAPIbefore using any methods in theSetupAPI.pasEdit, to provide some background: As simultaneously wrote by David in his answer and by me in my comment, the error is probably caused by calling an uninitialized method pointer. For me the first tip was the error message, an Access Violation: If the equivalent of an Access Violation came from Windows itself, it'd be called a
Runtime Error 216. The code is very simple, only uses constants and a method call. Constants can't generate AV's so the error had to come from the method itself, or from calling the method.Since the Delphi declaration supplied showed a "function type", I suspected
SetupOpenInfFileis actually an method pointer, not animportmethod. Those pointers need to somehow be initialized. SearchingSetupAPI.pas(thanks google for providing a link, because I don't use JEDI libraries) I quickly found that it's being assigned fromLoadSetupAPI. My first thought: isn'tLoadSetupAPIcalled from theinitializationsection? It's not, so it needs to be called from code. Problem solved.