add progId generator and example
This commit is contained in:
1 parent
b93e5eaf5d
commit
86864bbd09
7 files changed
+252
-80
No files matched your search
@@ -1,10 +1,26 @@
|
||||
#include "wfassoc.h"
|
||||
#include <strsafe.h>
|
||||
|
||||
// private function and variable declearions.
|
||||
|
||||
/// <summary>
|
||||
/// Convert multi byte string to wide char string
|
||||
/// Notice: this function will allocate memory for returns and it should be released safely.
|
||||
/// </summary>
|
||||
/// <param name="source">The string will be converted</param>
|
||||
/// <param name="error">The error happend during converting</param>
|
||||
/// <returns>The string has been converted. If return NULL, it mean that the converting failed.</returns>
|
||||
WCHAR* ConvMultiByteToWideChar(CHAR* source);
|
||||
|
||||
#define LEGACY_PROGID_FORMATA "%s.%s.%d"
|
||||
#define LEGACY_PROGID_FORMATW L"%s.%s.%d"
|
||||
#define SAFE_FREE(obj) if(obj!=NULL)free(obj);
|
||||
|
||||
// public function implements.
|
||||
|
||||
WFERROR WFInstallApplicationW(WFAPP_PROFILEW* profile) {
|
||||
if (profile->WFVersion != WFVERSION) return WFERROR_INVALID_VERSION;
|
||||
|
||||
return WFERROR_OK;
|
||||
}
|
||||
|
||||
@@ -13,6 +29,8 @@ WFERROR WFInstallApplicationA(WFAPP_PROFILEA* profile) {
|
||||
}
|
||||
|
||||
WFERROR WFUninstallApplicationW(WFAPP_PROFILEW* profile) {
|
||||
if (profile->WFVersion != WFVERSION) return WFERROR_INVALID_VERSION;
|
||||
|
||||
return WFERROR_OK;
|
||||
}
|
||||
|
||||
@@ -41,3 +59,27 @@ WFERROR WFGenerateProgIDA(CHAR* vendor, CHAR* component, INT version, CHAR* resu
|
||||
}
|
||||
return WFERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
// private function and variable implements.
|
||||
|
||||
WCHAR* ConvMultiByteToWideChar(CHAR* source) {
|
||||
WCHAR* dest = NULL;
|
||||
size_t sourceLength = strlen(source);
|
||||
|
||||
int destLength = MultiByteToWideChar(CP_ACP, 0, source, sourceLength, NULL, 0);
|
||||
if (destLength <= 0) return NULL;
|
||||
destLength += 10;
|
||||
|
||||
dest = (WCHAR*)malloc(sizeof(WCHAR) * destLength);
|
||||
if (dest == NULL) return NULL;
|
||||
|
||||
memset(dest, 0, sizeof(WCHAR) * destLength);
|
||||
int error = MultiByteToWideChar(CP_ACP, 0, source, sourceLength, dest, destLength);
|
||||
if (error <= 0) {
|
||||
free(dest);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
+44
-3
@@ -4,6 +4,22 @@
|
||||
#include <Windows.h>
|
||||
#include <sal.h>
|
||||
|
||||
// quick marco for developer and should not be used in wfassoc self
|
||||
|
||||
#ifdef UNICODE
|
||||
#define WFAPP_PROFILE WFAPP_PROFILEW
|
||||
#define WFInstallApplication WFInstallApplicationW
|
||||
#define WFUninstallApplication WFUninstallApplicationW
|
||||
#define WFGenerateProgID WFGenerateProgIDW
|
||||
#else
|
||||
#define WFAPP_PROFILE WFAPP_PROFILEA
|
||||
#define WFInstallApplication WFInstallApplicationA
|
||||
#define WFUninstallApplication WFUninstallApplicationA
|
||||
#define WFGenerateProgID WFGenerateProgIDA
|
||||
#endif
|
||||
|
||||
// useful macro
|
||||
|
||||
#define WFVERSION 0
|
||||
#define WFSUCCESS(expr) (!expr)
|
||||
#define WFFAILED(expr) expr
|
||||
@@ -25,9 +41,13 @@ typedef enum _WFERROR {
|
||||
/// </summary>
|
||||
WFERROR_INSUFFICIENT_BUFFER = 2,
|
||||
/// <summary>
|
||||
/// Some essential pointer variable is NULL
|
||||
/// Some essential pointer variable is NULL.
|
||||
/// </summary>
|
||||
WFERROR_NULLPTR = 3
|
||||
WFERROR_NULLPTR = 3,
|
||||
/// <summary>
|
||||
/// The encoding of string has error.
|
||||
/// </summary>
|
||||
WFERROR_ENCODING = 4
|
||||
}WFERROR;
|
||||
|
||||
/// <summary>
|
||||
@@ -64,8 +84,29 @@ typedef struct _WFAPP_PROFILEW {
|
||||
/// wfassoc Narrow Character Set Profile Struct
|
||||
/// </summary>
|
||||
typedef struct _WFAPP_PROFILEA {
|
||||
/// <summary>
|
||||
/// wfassoc version. Fill it with `WFVERSION` in your application. This field is used for version checking.
|
||||
/// </summary>
|
||||
INT WFVersion;
|
||||
CHAR* ApplicationName;
|
||||
/// <summary>
|
||||
/// The path to locate your application.
|
||||
/// </summary>
|
||||
CHAR* AppPath;
|
||||
/// <summary>
|
||||
/// The command will be executed when opening files.
|
||||
/// </summary>
|
||||
CHAR* AppCommand;
|
||||
/// <summary>
|
||||
/// Your application's ProgID.
|
||||
/// For more detail about how to create your ProgID, please browse: https://docs.microsoft.com/en-us/windows/win32/shell/fa-progids
|
||||
/// We also provide a generator for creating legacy ProgID. Use `WFGenerateProgID` to create a legacy ProgID.
|
||||
/// </summary>
|
||||
CHAR* ProgID;
|
||||
/// <summary>
|
||||
/// Your application supported file extensions.
|
||||
/// The structure of this field is connecting all supported extensions with dot(.) end to end. For example:
|
||||
/// `.jpg\0.png\0.gif\0`
|
||||
/// </summary>
|
||||
CHAR* SupportedTypes;
|
||||
}WFAPP_PROFILEA;
|
||||
|
||||
|
||||
@@ -72,9 +72,11 @@
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)builds\Debug\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)builds\Release\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
|
||||
Reference in new issue
Block a user