winapi - How to set current directory while working with an OLE Automation Server -
i trying create ole exe server's instance through createdispatch
call apparently fails because current directory not correct. error "server initialization failed". debugged createdispatch
code , found out 3 things.
- cocreateinstance //in case succeeds
- olerun //this fails in case error 'server execution failed'
- queryinterface idispatch
i tried launch process through createprocess
fails if don't provide correct currentdirectory
in 8th argument means in case currentdirectory
not correct , have provide working.
i know parent's currentdirectory
passed on when parent trying spawn process. so, tried changing parent's currentdirectory
appropriate directory via setcurrentdirectory
api call. works in case of createprocess
doesn't work in case of createdispatch
giving me same error , failing on same olerun
call inside.
does have idea how can pass on currentdirectory createdispatch
? or there workaround?
if need have currect directory set application directory, shoul djust thi sin "main" of program. can getmodulefilename
, use splitpath
directory , tehn call setcurrentdirectory
.
#include <windows.h> #include <stdio.h> #include <tchar.h> int _tmain() { tchar szdrive[_max_drive]; tchar szpath[_max_path]; tchar szname[_max_fname]; tchar szext[_max_ext]; tchar szmodname[max_path]; getmodulefilename(null, szmodname, max_path); _tsplitpath(szmodname, szdrive, szpath, szname, szext); tchar szappdir[max_path]; _tcscpy_s(szappdir, szdrive); _tcscat_s(szappdir, szpath); setcurrentdirectory(szappdir); _tprintf(szappdir); }
Comments
Post a Comment