Add new files
[juce-lv2.git] / juce_lv2_ttl_generator.c
blob70d3a882b182ff50bb566af88e7bdfb954c0daca
1 /*
2 * JUCE LV2 *.ttl generator
3 */
5 #include <stdio.h>
7 #if defined(_WIN32) || defined (_WIN64)
8 #include <windows.h>
9 #define TTL_GENERATOR_WINDOWS
10 #else
11 #include <dlfcn.h>
12 #endif
14 typedef void (*TTL_Generator_Function)(void);
16 int main(int argc, char *argv[])
18 if (argc != 2) {
19 printf("usage: %s /path/to/binary.so\n", argv[0]);
20 return 1;
23 #ifdef TTL_GENERATOR_WINDOWS
24 void* handle = LoadLibrary(argv[1]);
25 #else
26 void* handle = dlopen(argv[1], RTLD_LAZY);
27 #endif
29 if (!handle) {
30 #ifdef TTL_GENERATOR_WINDOWS
31 printf("Failed to open library\n");
32 #else
33 printf("Failed to open library, error was:\n%s\n", dlerror());
34 #endif
35 return 2;
38 #ifdef TTL_GENERATOR_WINDOWS
39 TTL_Generator_Function ttl_fcn = (TTL_Generator_Function)GetProcAddress((HMODULE)handle, "juce_lv2_ttl_generator");
40 #else
41 TTL_Generator_Function ttl_fcn = (TTL_Generator_Function)dlsym(handle, "juce_lv2_ttl_generator");
42 #endif
44 if (ttl_fcn) {
45 ttl_fcn();
46 } else {
47 printf("Failed to find 'juce_lv2_ttl_generator' function\n");
50 #ifdef TTL_GENERATOR_WINDOWS
51 FreeLibrary((HMODULE)handle);
52 #else
53 dlclose(handle);
54 #endif
56 return 0;