Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VC++ to Delphi 2

Status
Not open for further replies.

lucky34238

Programmer
May 20, 2006
18
0
0
US
Can anyone convert this vc++ to Delphi?

Thank you.

-------------------------------

#include <windows.h>
#include <msi.h>
#include <ostream.h>

const char *Word = "{CC29E963-7BC2-11D1-A921-00A0C91E2AA2}";
const char *Excel = "{CC29E96F-7BC2-11D1-A921-00A0C91E2AA2}";
const char *PowerPoint = "{CC29E94B-7BC2-11D1-A921-00A0C91E2AA2}";
const char *Access = "{CC29E967-7BC2-11D1-A921-00A0C91E2AA2}";
const char *Office = "{00000409-78E1-11D2-B60F-006097C998E7}";

int main(void)
{
DWORD size = 300;
INSTALLSTATE installstate;
char *sPath;

sPath = new char[size];
installstate = MsiGetComponentPath(
Office,Word,sPath,&size);

if ((installstate == INSTALLSTATE_LOCAL) ||
(installstate == INSTALLSTATE_SOURCE))
cout << "Installed in: " << sPath << endl;
delete sPath;
return 0;
}
 
not too hard:

Code:
unit MsiDemo;

interface  

 
uses  
  ShlObj, ComObj, ActiveX, CommCtrl, Windows, SysUtils;  


const 

Guid_Word = '{CC29E963-7BC2-11D1-A921-00A0C91E2AA2}';
Guid_Excel = '{CC29E96F-7BC2-11D1-A921-00A0C91E2AA2}';
Guid_PowerPoint = '{CC29E94B-7BC2-11D1-A921-00A0C91E2AA2}';
Guid_Access = '{CC29E967-7BC2-11D1-A921-00A0C91E2AA2}';
Guid_Office = '{00000409-78E1-11D2-B60F-006097C998E7}';

const  
  MsiDllName                = 'msi.dll';  

 
  INSTALLSTATE_ABSENT       =  2;    // uninstalled  
  INSTALLSTATE_LOCAL        =  3;    // installed on local drive  
  INSTALLSTATE_SOURCE       =  4;    // run from source, CD or net  
  INSTALLSTATE_SOURCEABSENT = -4;    // run from source, source is unavailable  
  INSTALLSTATE_NOTUSED      = -7;    // component disabled  
  INSTALLSTATE_INVALIDARG   = -2;    // invalid function argument  
  INSTALLSTATE_UNKNOWN      = -1;    // unrecognized product or feature  
type  
  TINSTALLSTATE              = LongInt;  

TMsiGetComponentPath      = function(szProduct, szComponent: PAnsiChar;  
    lpPathBuf: PAnsiChar; pcchBuf: pdword): INSTALLSTATE; stdcall;  
var  
  MsiGetComponentPath       : TMsiGetComponentPath  = nil;  
  MsiDll                    : dword = 0;  

implementation 

procedure main;

var sPath : string;
    installstate : TINSTALLSTATE;  
    size : dword;

begin
 size:=300;
 Setlength(sPath, size);  
 installstate := MsiGetComponentPath(
        Pchar(Guid_Office),Pchar(Guid_Word),sPath,@size);

    if ((installstate = INSTALLSTATE_LOCAL) or 
            (installstate = INSTALLSTATE_SOURCE)) then
        begin
         showmessage(Format('installed in: %s' ,[sPath]));
        end;
end;

initialization  
  MsiDll                     := GetModuleHandle(MsiDllName);  
  if(MsiDll = 0) then MsiDll := LoadLibrary(MsiDllName);  

 
  if(MsiDll <> 0) then  
  begin  
    MsiGetComponentPath      := GetProcAddress(MsiDll, 'MsiGetComponentPathA');  

 
   @MsiGetComponentPath  = nil then  
    begin  
      FreeLibrary(MsiDll);  
      MsiDll := 0;  
    end;  
  end;  

 
finalization  
  if(MsiDll <> 0) then FreeLibrary(MsiDll);  

end.

this code is untested, but I think you get the picture...

//Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
whosrdaddy,

You are awesome. I am learning from your code, and do you have any reference that one could relate c++ code into Delphi or vice versa.

I want to give your answer 5 stars but I don't know how to do it in this forum.

Thanks again.

Lucky
 
np man, we're here to help!


[afro2]


-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top