Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Platform invoke???

Platform invoke???

Scheduled Pinned Locked Moved C#
question
18 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Vu Truong

    Hi all, using System.Runtime.InteropServices; ... [DllImport("ole32.dll")] public static extern long CLSIDFromProgID(string ProgID, out Guid clsID); ... Guid clsID; long ret = CLSIDFromProgID("Excel.Application", out clsID); if(ret==0) System.Console.WriteLine("OK."); else System.Console.WriteLine("Fail."); I use above codes for checking Microsoft Excel is installed or not. But it doesn't work at all, even if I already installed Microsoft Excel. Are there any missing in my codes?

    S Offline
    S Offline
    Stephane Rodriguez
    wrote on last edited by
    #2

    [DllImport("ole32.dll", CharSet=CharSet.Auto)]


    She's so dirty, she threw a boomerang and it wouldn't even come back.

    V 1 Reply Last reply
    0
    • S Stephane Rodriguez

      [DllImport("ole32.dll", CharSet=CharSet.Auto)]


      She's so dirty, she threw a boomerang and it wouldn't even come back.

      V Offline
      V Offline
      Vu Truong
      wrote on last edited by
      #3

      Hi Stephane, Thanks for your help. I changed my codes as you suggest but it still doesn't work. I think I don't set type of parameters accurately. Do you think my declaration below is correct? [DllImport("ole32.dll", CharSet=CharSet.Auto)] public static extern long CLSIDFromProgID(string ProgID, out Guid clsID); Many thanks.

      1 Reply Last reply
      0
      • V Vu Truong

        Hi all, using System.Runtime.InteropServices; ... [DllImport("ole32.dll")] public static extern long CLSIDFromProgID(string ProgID, out Guid clsID); ... Guid clsID; long ret = CLSIDFromProgID("Excel.Application", out clsID); if(ret==0) System.Console.WriteLine("OK."); else System.Console.WriteLine("Fail."); I use above codes for checking Microsoft Excel is installed or not. But it doesn't work at all, even if I already installed Microsoft Excel. Are there any missing in my codes?

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #4

        The return type is a 32-bit integer, which is int, not long. Have you tried:

        Type Excel = Type.GetTypeFromProgID("Excel.Application");
        if (Excel == null)
        Console.WriteLine("Fail.");
        else
        Console.WriteLine("OK.");

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • V Vu Truong

          Hi all, using System.Runtime.InteropServices; ... [DllImport("ole32.dll")] public static extern long CLSIDFromProgID(string ProgID, out Guid clsID); ... Guid clsID; long ret = CLSIDFromProgID("Excel.Application", out clsID); if(ret==0) System.Console.WriteLine("OK."); else System.Console.WriteLine("Fail."); I use above codes for checking Microsoft Excel is installed or not. But it doesn't work at all, even if I already installed Microsoft Excel. Are there any missing in my codes?

          E Offline
          E Offline
          Eric Gunnerson msft
          wrote on last edited by
          #5

          Can you explain what you're trying to do? If you're trying to drive excel, you'd do that through COM interop, not through P/Invoke. You do that by adding the excel com component to your project (or through tlbimp if you don't have vs).

          J D V 3 Replies Last reply
          0
          • E Eric Gunnerson msft

            Can you explain what you're trying to do? If you're trying to drive excel, you'd do that through COM interop, not through P/Invoke. You do that by adding the excel com component to your project (or through tlbimp if you don't have vs).

            J Offline
            J Offline
            Jorgen Sigvardsson
            wrote on last edited by
            #6

            How would such an interop assembly behave on a system where excel is not installed? Would it crap out on me while loading the application or would it throw a bunch of exceptions at me when I try to instantiate the COM-objects? -- Please state the nature of your medical emergency.

            E 1 Reply Last reply
            0
            • E Eric Gunnerson msft

              Can you explain what you're trying to do? If you're trying to drive excel, you'd do that through COM interop, not through P/Invoke. You do that by adding the excel com component to your project (or through tlbimp if you don't have vs).

              D Offline
              D Offline
              David Stone
              wrote on last edited by
              #7

              Ummm, Eric your company is giving us this: http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/999/msdncompositedoc.xml[^] and they say to use that instead of doing any type of COM stuff. Just thought I'd let you know. :) Norm Almond: I seen some GUI's in my life but WTF is this mess ;-) Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough:) Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children:laugh: Leppie:My sister is 25:eek: -Norm on the MailMagic GUI

              E 1 Reply Last reply
              0
              • E Eric Gunnerson msft

                Can you explain what you're trying to do? If you're trying to drive excel, you'd do that through COM interop, not through P/Invoke. You do that by adding the excel com component to your project (or through tlbimp if you don't have vs).

                V Offline
                V Offline
                Vu Truong
                wrote on last edited by
                #8

                Thanks for your reply. I use Microsoft Excel Object Library to create and edit on Excel files. So I have to make sure that Microsoft Excel is already installed. I also want to check I can use ADOX on the user's computer or not. I think if getting CLSID of these components successfully, I can use them. Is it right?

                1 Reply Last reply
                0
                • D David Stone

                  Ummm, Eric your company is giving us this: http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/999/msdncompositedoc.xml[^] and they say to use that instead of doing any type of COM stuff. Just thought I'd let you know. :) Norm Almond: I seen some GUI's in my life but WTF is this mess ;-) Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough:) Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children:laugh: Leppie:My sister is 25:eek: -Norm on the MailMagic GUI

                  E Offline
                  E Offline
                  Eric Gunnerson msft
                  wrote on last edited by
                  #9

                  I didn't know we'd made those available. The page you link is correct, you should use the primary interop assemblies rather than rolling your own.

                  J D 2 Replies Last reply
                  0
                  • J Jorgen Sigvardsson

                    How would such an interop assembly behave on a system where excel is not installed? Would it crap out on me while loading the application or would it throw a bunch of exceptions at me when I try to instantiate the COM-objects? -- Please state the nature of your medical emergency.

                    E Offline
                    E Offline
                    Eric Gunnerson msft
                    wrote on last edited by
                    #10

                    Hmm. I don't know the answer to that.

                    1 Reply Last reply
                    0
                    • E Eric Gunnerson msft

                      I didn't know we'd made those available. The page you link is correct, you should use the primary interop assemblies rather than rolling your own.

                      J Offline
                      J Offline
                      Jorgen Sigvardsson
                      wrote on last edited by
                      #11

                      Eric Gunnerson (msft) wrote: you should use the primary interop assemblies rather than rolling your own Any special reason for this? -- Please state the nature of your medical emergency.

                      E 1 Reply Last reply
                      0
                      • J Jorgen Sigvardsson

                        Eric Gunnerson (msft) wrote: you should use the primary interop assemblies rather than rolling your own Any special reason for this? -- Please state the nature of your medical emergency.

                        E Offline
                        E Offline
                        Eric Gunnerson msft
                        wrote on last edited by
                        #12

                        The big reason is that they're signed.

                        N 1 Reply Last reply
                        0
                        • E Eric Gunnerson msft

                          The big reason is that they're signed.

                          N Offline
                          N Offline
                          Nick Parker
                          wrote on last edited by
                          #13

                          Eric Gunnerson (msft) wrote: The big reason is that they're signed. Sounds like political red tape typical from any company, am I right?... ;) Nick Parker
                          **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


                          **

                          E 1 Reply Last reply
                          0
                          • N Nick Parker

                            Eric Gunnerson (msft) wrote: The big reason is that they're signed. Sounds like political red tape typical from any company, am I right?... ;) Nick Parker
                            **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


                            **

                            E Offline
                            E Offline
                            Eric Gunnerson msft
                            wrote on last edited by
                            #14

                            Nick Parker wrote: Sounds like political red tape typical from any company, am I right?... I don't understand your point.

                            N 1 Reply Last reply
                            0
                            • E Eric Gunnerson msft

                              Nick Parker wrote: Sounds like political red tape typical from any company, am I right?... I don't understand your point.

                              N Offline
                              N Offline
                              Nick Parker
                              wrote on last edited by
                              #15

                              Eric Gunnerson (msft) wrote: I don't understand your point. I was only being facetious. Just trying to lighten things up in the C# forum. No bad feelings? ;) Nick Parker
                              **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


                              **

                              1 Reply Last reply
                              0
                              • E Eric Gunnerson msft

                                I didn't know we'd made those available. The page you link is correct, you should use the primary interop assemblies rather than rolling your own.

                                D Offline
                                D Offline
                                David Stone
                                wrote on last edited by
                                #16

                                How much stuff do you not make available to us??? :suss: Norm Almond: I seen some GUI's in my life but WTF is this mess ;-) Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough:) Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children:laugh: Leppie:My sister is 25:eek: -Norm on the MailMagic GUI

                                E 1 Reply Last reply
                                0
                                • D David Stone

                                  How much stuff do you not make available to us??? :suss: Norm Almond: I seen some GUI's in my life but WTF is this mess ;-) Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough:) Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children:laugh: Leppie:My sister is 25:eek: -Norm on the MailMagic GUI

                                  E Offline
                                  E Offline
                                  Eric Gunnerson msft
                                  wrote on last edited by
                                  #17

                                  This much (holding hands about 3 feet apart)... Perhaps "released" would have been a better term.

                                  D 1 Reply Last reply
                                  0
                                  • E Eric Gunnerson msft

                                    This much (holding hands about 3 feet apart)... Perhaps "released" would have been a better term.

                                    D Offline
                                    D Offline
                                    David Stone
                                    wrote on last edited by
                                    #18

                                    Okay. Just wanted one more reason to work at Microsoft...:-D Norm Almond: I seen some GUI's in my life but WTF is this mess ;-) Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough:) Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children:laugh: Leppie:My sister is 25:eek: -Norm on the MailMagic GUI

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups