1
0
Files
wfassoc/wfassoc_example/main.c

82 lines
2.0 KiB
C
Raw Permalink Normal View History

2022-02-01 10:54:27 +08:00
#include "../wfassoc/wfassoc.h"
#include <stdio.h>
2022-02-18 14:53:49 +08:00
#include <tchar.h>
2022-02-01 10:54:27 +08:00
#define COMMAND_MAX_LENGTH 128
2022-02-18 14:53:49 +08:00
WFAPP_PROFILE* create_profile();
TCHAR* create_progId();
void free_profile(WFAPP_PROFILE* profile);
2022-02-01 10:54:27 +08:00
int main(int argc, char* args[]) {
2022-02-18 14:53:49 +08:00
// alloc application profile
WFAPP_PROFILE* profile = create_profile();
if (profile == NULL) {
puts("Error: Fail to allocating profile structure.\n");
return 1;
}
2022-02-01 10:54:27 +08:00
// alloc input string and check it
char* input_str = malloc(sizeof(char) * (COMMAND_MAX_LENGTH + 1));
if (input_str == NULL) return;
2022-02-18 14:53:49 +08:00
2022-02-01 10:54:27 +08:00
// accept input
while (TRUE) {
gets_s(input_str, COMMAND_MAX_LENGTH);
if (!strcmp(input_str, "install")) {
2022-02-18 14:53:49 +08:00
_tprintf(TEXT("%s\n"), profile->ProgID);
2022-02-01 10:54:27 +08:00
} else if (!strcmp(input_str, "uninstall")) {
2022-02-18 14:53:49 +08:00
_tprintf(TEXT("%s\n"), profile->ProgID);
2022-02-01 10:54:27 +08:00
} else if (!strcmp(input_str, "quit")) {
break;
}
}
//free input string
free(input_str);
2022-02-18 14:53:49 +08:00
return 0;
2022-02-01 10:54:27 +08:00
}
2022-02-18 14:53:49 +08:00
WFAPP_PROFILE* create_profile() {
WFAPP_PROFILE* profile = (WFAPP_PROFILE*)malloc(sizeof(WFAPP_PROFILE));
2022-02-01 10:54:27 +08:00
if (profile == NULL) return NULL;
2022-02-18 14:53:49 +08:00
memset(profile, 0, sizeof(WFAPP_PROFILE));
2022-02-01 10:54:27 +08:00
profile->WFVersion = WFVERSION;
2022-02-18 14:53:49 +08:00
profile->AppPath = TEXT("E:\\pineapple-picture\\ppic.exe");
profile->AppCommand = TEXT("E:\\pineapple-picture\\ppic.exe \"%1\"");
profile->SupportedTypes = TEXT(".png\0.jpg\0");
2022-02-01 10:54:27 +08:00
profile->ProgID = create_progId();
if (profile->ProgID == NULL) {
free_profile(profile);
return NULL;
}
return profile;
}
2022-02-18 14:53:49 +08:00
TCHAR* create_progId() {
TCHAR* progid = NULL;
2022-02-01 10:54:27 +08:00
int progIdSize;
2022-02-18 14:53:49 +08:00
if (WFFAILED(WFGenerateProgID(TEXT("PineapplePicture"), TEXT("Image"), 0, NULL, &progIdSize))) {
2022-02-01 10:54:27 +08:00
return NULL;
}
2022-02-18 14:53:49 +08:00
progid = (TCHAR*)malloc(sizeof(TCHAR) * progIdSize);
2022-02-01 10:54:27 +08:00
if (progid == NULL) return NULL;
2022-02-18 14:53:49 +08:00
memset(progid, 0, sizeof(TCHAR) * progIdSize);
2022-02-01 10:54:27 +08:00
2022-02-18 14:53:49 +08:00
if (WFFAILED(WFGenerateProgID(TEXT("PineapplePicture"), TEXT("Image"), 0, progid, &progIdSize))) {
2022-02-01 10:54:27 +08:00
free(progid);
return NULL;
}
return progid;
}
2022-02-18 14:53:49 +08:00
void free_profile(WFAPP_PROFILE* profile) {
2022-02-01 10:54:27 +08:00
if (profile->ProgID != NULL) free(profile->ProgID);
free(profile);
}