I am writing a tiny webcam control application in Delphi. I have a sample C ++ code sample and I need to rewrite it in Delphi as part of my application. Everything works fine in Delphi, except for one method call that crashes "Access violation at address 63252469 in module" vidcap.ax ". Address message 11D206FD."
Here is the part of the C ++ code example that works (without error handling):
#include <vidcap.h> // For IKsTopologyInfo #include <ksproxy.h> // For IKsControl .... //pKsTopologyInfo is passed from the outside IKsControl *pKsControl = NULL; DWORD dwNumNodes = 0; pKsTopologyInfo->get_NumNodes(&dwNumNodes); for(unsigned int i = 0; i < dwNumNodes; i++) { pKsTopologyInfo->get_NodeType(i, &guidNodeType); if(IsEqualGUID(guidNodeType, KSNODETYPE_DEV_SPECIFIC)) { hr = pKsTopologyInfo->CreateNodeInstance(i, IID_IKsControl, (void **)&pKsControl);
And here is the relevant part of my code in Delphi:
//KsTopologyInfo is IKsTopologyInfo passed from the outside //pKsControl is ^IKsControl, which is taken from DirectShow9.pas from DSPack components set. KsTopologyInfo.get_NumNodes(@dwNumNodes); for i:=0 to dwNumNodes-1 do begin KsTopologyInfo.get_NodeType(i,@guidNodeType); if IsEqualGUID(guidNodeType,KSNODETYPE_DEV_SPECIFIC) then begin KsTopologyInfo.CreateNodeInstance(i,IID_IKsControl,@pKsControl);
The error occurs in Delphi code on the last line here, but in C ++ it is excellent.
The check in the step-by-step debugger shows no differences - in both Delphi and C ++ it gets 11 for dwNumNodes, then IsEqualGUID returns TRUE when I == 3 and guidNodeType == {941C7AC0-C559-11D0-8A2B-00A0C9255AC1}. Therefore, in both cases, it calls CreateNodeInstance with the same values ββi = 3 and IID_IKsControl = {28F54685-06FD-11D2-B27A-00A0C9223196}
Unfortunately, I could not find vidcap.h converted to a Delphi.pas file, so I wrote my own description for IKsTopologyInfo, and I believe that I have an error in the description of the CreateNodeInstance method. Here it is from vidcap.h:
virtual HRESULT STDMETHODCALLTYPE CreateNodeInstance( DWORD dwNodeId, REFIID iid, void **ppvObject) = 0;
And here is my option for Delphi:
function CreateNodeInstance(dwNodeId:DWord; iid:TGuid; p:Pointer):HRESULT; stdcall;
I tried many options with the third parameter - var Obj, Pointer, PPointer (which is ^ Pointer), and also tried to pass it different values ββof the options (IKsControl, ^ IKsControl, ^ (^ IKsControl), Pointer, ^ Pointer - and none of They donβt work. In any case, I got the same error.
You need any tips on how to make it work, and how to look correct. Description IKsTopologyInfo.CreateNodeInstance and call in Delphi.