Hi -
I think I am experiencing the same kind of problem that the OP has. What I am trying to do is open up a file, go through all of the block references and explode with the "-explode" command. I'm doing this through VB.NET via a "SendCommand" call. I know the handle to the block ref, so I do this:
acadDoc.SendCommand("(command ""-explode"" (handent """ & strHandle & """))" & vbCrLf)
The problem is that works once, and subsequent calls blow up with the "call rejected by callee" exception. I'm suspecting it's the same deal as the OP. One other wierdness is when I call that, AutoCAD's help file pops up. AutoCAD's main window also tends to want to show itself as well, no matter what I set it's visibility to.
With that said, I'm trying to get this EnumWindows thing working, and I was wondering if you could post the rest of the code. I'm having problems declaring the Win32 API functions, and nothing I've found on the web is working. I'm assuming that something like this should work:
Public Delegate Function CallBack(ByVal handle As Integer, ByVal param As Integer) As Boolean
Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As CallBack, _
ByVal lParam As Integer) As Integer
Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, _
ByVal lpString As String, ByVal cch As Long) As Long
Private Const WM_KEYUP As Long = &H101
Public Function WndEnumProc(ByVal handle As Integer, _
ByVal param As Integer) As Boolean
Dim lResult As Long
Dim sWndName As String
WndEnumProc = 1
lResult = GetWindowText(handle, sWndName, 255)
' And I assume that if sWndName has "AutoCAD" in it
' or something like that, we set gAutoCADHwnd to it
End Function
I have to do the "Callback" thing apprarently because the AddressOf thing needs it based on the MSDN docs.
The problem I see is that GetWindowText is not giving me anything at all. lResult is garbage. If I set a breakpoint and go through, I get LOTS AND LOTS of handles, seemingly more than I expect, and nothing with which GetWindowText works.
One other question tho - Instead of using EnumWindows, why not use AcadApplication.HWND? I still don't have any success doing a PostMessage to that, but I'm still curious. I know this is a hairy question, but any help is appreciated.
Thanks!