Autor Beitrag
Mr_Sven
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38


D7 Prof., C# (VS 2008)
BeitragVerfasst: Mo 16.01.06 17:10 
Hi,
ich habe ein Problem mit einem OLE / COM zugriff.

Ich habe ein Programm was eine DLL läd, die wiederum auf ein COM Object zugreift.

Wenn ich das Programm starte bevor der COM Server startet, dann klappt es.
Sobald die DLL neu geladen wird, oder ich mein Programm nach dem COM Server starte, dann schmiert das
Programm mit einer Access Violation ab.

Ich habe auch schon mit CoInitializeEx rumprobiert, aber es ändert sich nix.

Kann mir jemand helfen?

Gruß Sven

Hier das Stück Code aus der DLL
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
 if not MemInitialized then
  try
   OLECheck(CoInitializeEx(nil, COINIT_APARTMENTTHREADED));
  except
   on E:Exception do
    begin
     log('couldn´t init COM system: ' + E.Message,lDebug);
     Exit;
    end;
   end;
 MemInitialized:=true;
 
 if not NotesWasOpen and NotesSessionOpen then
  MySession:= createOLEObject('Notes.NotesSession');
Mr_Sven Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38


D7 Prof., C# (VS 2008)
BeitragVerfasst: Di 24.01.06 15:07 
So, nachdem ich alles erdenkliche getraced und gedebugged hab, habe ich
endlich den Source soweit, dass nix mehr abschmiert.

Gruß Sven
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
function LNCreateOleObject(const ClassName: string): IDispatch;
var
  ClassID: TCLSID;
begin
  ClassID := ProgIDToClassID(ClassName);
  OleCheck(CoCreateInstance(ClassID, nil, CLSCTX_INPROC_SERVER or 
                                          CLSCTX_LOCAL_SERVER or 
                                          CLSCTX_INPROC_HANDLER, IDispatch, Result));
end;

....
 if not NotesWasOpen and NotesSessionOpen then
  begin          
   if not MemInitialized then
    begin
     OleInitialize(nil);
     MemInitialized:=true;
    end;
   MySession:= LNcreateOLEObject('Notes.NotesSession');
  end;

 if NotesSessionOpen then
  begin
   if VarIsEmpty(MySession) or LNVarIsEmpty(MySession) then
    MySession:= LNcreateOLEObject('Notes.NotesSession');

   try
    MySession.NotesVersion;
   except
    on E:Exception do
     begin
      if E is EOleSysError then
       MySession:= LNcreateOLEObject('Notes.NotesSession');
     end;
   end;
 end;


PS: hatte was vergesse