Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

AssocCreate (shlwapi)
 
.
Summary
TODO - a short description

C# Signature:

[DllImport("shlwapi.dll")]
extern static int AssocCreate(
   ref Guid clsid,
   ref Guid riid,
   [MarshalAs(UnmanagedType.Interface)] out object ppv);

VB Signature:

Declare Function AssocCreate Lib "shlwapi.dll" (TODO) As TODO

User-Defined Types:

[Flags]
enum ASSOCF
{
   INIT_NOREMAPCLSID = 0x00000001,
   INIT_BYEXENAME = 0x00000002,
   OPEN_BYEXENAME = 0x00000002,
   INIT_DEFAULTTOSTAR = 0x00000004,
   INIT_DEFAULTTOFOLDER = 0x00000008,
   NOUSERSETTINGS = 0x00000010,
   NOTRUNCATE = 0x00000020,
   VERIFY = 0x00000040,
   REMAPRUNDLL = 0x00000080,
   NOFIXUPS = 0x00000100,
   IGNOREBASECLASS = 0x00000200,
   INIT_IGNOREUNKNOWN = 0x00000400
}

enum ASSOCSTR
{
   COMMAND = 1,
   EXECUTABLE,
   FRIENDLYDOCNAME,
   FRIENDLYAPPNAME,
   NOOPEN,
   SHELLNEWVALUE,
   DDECOMMAND,
   DDEIFEXEC,
   DDEAPPLICATION,
   DDETOPIC,
   INFOTIP,
   QUICKTIP,
   TILEINFO,
   CONTENTTYPE,
   DEFAULTICON,
   SHELLEXTENSION
}

enum ASSOCKEY
{
   SHELLEXECCLASS = 1,
   APP,
   CLASS,
   BASECLASS
}

enum ASSOCDATA
{
   MSIDESCRIPTOR = 1,
   NOACTIVATEHANDLER,
   QUERYCLASSSTORE,
   HASPERUSERASSOC,
   EDITFLAGS,
   VALUE
}

[Guid("c46ca590-3c3f-11d2-bee6-0000f805ca57"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IQueryAssociations
{
   void Init(
     [In] ASSOCF flags,
     [In, MarshalAs(UnmanagedType.LPWStr)] string pszAssoc,
     [In] UIntPtr hkProgid,
     [In] IntPtr hwnd);

   void GetString(
     [In] ASSOCF flags,
     [In] ASSOCSTR str,
     [In, MarshalAs(UnmanagedType.LPWStr)] string pwszExtra,
     [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszOut,
     [In, Out] ref int pcchOut);

   void GetKey(
     [In] ASSOCF flags,
     [In] ASSOCKEY str,
     [In, MarshalAs(UnmanagedType.LPWStr)] string pwszExtra,
     [Out] out UIntPtr phkeyOut);

   void GetData(
     [In] ASSOCF flags,
     [In] ASSOCDATA data,
     [In, MarshalAs(UnmanagedType.LPWStr)] string pwszExtra,
     [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] out byte[] pvOut,
     [In, Out] ref int pcbOut);

   void GetEnum(); // not used actually
}

static Guid CLSID_QueryAssociations = new Guid("a07034fd-6caa-4954-ac3f-97a27216f98a");
static Guid IID_IQueryAssociations = new Guid("c46ca590-3c3f-11d2-bee6-0000f805ca57");

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

try
{
   object obj;
   AssocCreate(
     ref CLSID_QueryAssociations,
     ref IID_IQueryAssociations,
     out obj);
   IQueryAssociations qa = (IQueryAssociations)obj;
   qa.Init(
     ASSOCF.INIT_DEFAULTTOSTAR,
     ".doc",
     UIntPtr.Zero, IntPtr.Zero);

   int size = 0;
   qa.GetString(ASSOCF.NOTRUNCATE, ASSOCSTR.COMMAND,
     "print", null, ref size);

   StringBuilder sb = new StringBuilder(size);
   qa.GetString(ASSOCF.NOTRUNCATE, ASSOCSTR.COMMAND,
     "print", sb, ref size);

   Console.WriteLine(".doc is printed by : {0}", sb.ToString());
}
catch(Exception e)
{
   if((uint)Marshal.GetHRForException(e) == 0x80070483)
     Console.WriteLine("No command line is associated to .doc print verb.");
   else
     throw;
}

Documentation
AssocCreate on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions