且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以调试VS2008中的COM DLL?

更新时间:2023-01-17 12:05:19

,是的,你可以逐步通过逐个指令的COM方法实现的代码。



然而,即使你知道程序集很好,并且明确地知道所有的处理器指令是如何工作的,这是一个很高的顺序来调试别人的代码在这种方式,除非它是一个真正的,真的很简单的方法。



如果你对汇编程序不熟悉,甚至不要考虑它,除非你准备好几周的学习曲线。



如果COM方法似乎没有按照您期望的方式工作,我将首先尝试使用非托管代码测试方法(例如C ++ ),因为你的问题可能在COM Interop编组,而不是在COM方法本身。


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;

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.