Is it possible to debug a COM dll in VS2008?

谁说胖子不能爱 提交于 2019-12-12 16:16:09

问题


This may be a very stupid question.
Is it possible to debug a COM dll in VS2008 for which I do not have the source code?

The reason I want to do this is I am passing an Array to a COM method and I expect this Array to be populated by the method.
However the Array is not being populated. So I want to step into the COM method to see whats happening. is this possible?

Below is an example of the code I am using:

Array binaryArray = Array.CreateInstance(typeof(sbyte), 896);
bool success = photo.GetBinaryData(binaryArray);

IDL for the GetBinaryData method:

[id(0x000000c9)]
HRESULT GetBinaryData(
                [in] SAFEARRAY(char) buffer, 
                [out, retval] VARIANT_BOOL* retval);

The GetBinaryData method is the COM method which I would like to step into.

EDIT: Adding a Delphi test script which works

procedure TComTestForm.TestUserBtnClick(Sender: TObject);
var
  nCnt :integer;
  User :IUser;
  Persona :IUserPersona;
  ArrayBounds :TSafeArrayBound;
  ArrayData :Pointer;
  TagList :PSafeArray;
  nSize :integer;
begin
  User := Session.GetUser;

  ArrayBounds.lLbound   := 0;
  ArrayBounds.cElements := 0;

  TagList := SafeArrayCreate( varInteger, 1, ArrayBounds );
  User.GetTags( TagList );
  if SafeArrayAccessData( TagList, ArrayData ) = S_OK then
    begin
      nSize := TagList.rgsabound[0].cElements;
      OutLine( '----Available Tags, ' + IntToStr(nSize) + ' tags' );
  for nCnt := 0 to nSize - 1 do
    begin
  OutLine( IntToStr( IntegerArray(ArrayData)[nCnt] ) );
end;

OutLine( '----');

SafeArrayUnAccessData( TagList ); SafeArrayDestroy( TagList ); end;

end;


回答1:


In principle, yes, you can step through the code of the COM method implementation instruction-by-instruction.

However, even if you know assembly well and understand exactly how all the processor instructions work, it's a tall order to debug someone else's code in this fashion unless it's a really, really simple method.

If you are new to assembler, don't even consider it unless you're prepared to do weeks of learning curve first.

If the COM method doesn't appear to be working in the way you expected based on its documentation, I would first try to test the method using unmanaged code (e.g. C++), as your problem may be in the COM Interop marshalling rather than in the COM method itself.



来源:https://stackoverflow.com/questions/5910061/is-it-possible-to-debug-a-com-dll-in-vs2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!