int main(int argc, char **argv) { void *handle; char *err; if ((HostLibBase = OpenResource("hostlib.resource")) == NULL) { fprintf(stderr, "can't open hostlib.resource\n"); return 1; } if ((handle = HostLib_Open("libSDL.so", &err)) == NULL) { fprintf(stderr, "can't open sdl: %s\n", err); return 1; } SDL_Init = HostLib_GetPointer(handle, "SDL_Init", NULL); SDL_SetVideoMode = HostLib_GetPointer(handle, "SDL_SetVideoMode", NULL); SDL_Quit = HostLib_GetPointer(handle, "SDL_Quit", NULL); SDL_Init(0x20); SDL_SetVideoMode(640, 480, 16, 0); Delay(250); SDL_Quit(); HostLib_Close(handle, NULL); return 0; }
/* auto init */ static int BattClock_Init(struct BattClockBase *BattClockBase) { APTR HostLibBase; ULONG r; HostLibBase = OpenResource("hostlib.resource"); D(bug("[battclock] HostLibBase = 0x%08lX\n", HostLibBase)); if (HostLibBase) { BattClockBase->Lib = HostLib_Open(LIBC_NAME, NULL); if (BattClockBase->Lib) { BattClockBase->SysIFace = (struct BattclockInterface *)HostLib_GetInterface(BattClockBase->Lib, Symbols, &r); D(bug("[battclock] SysIFace = 0x%08lX, unresolved: %u\n", BattClockBase->SysIFace, r)); if (BattClockBase->SysIFace) { if (!r) return 1; HostLib_DropInterface((APTR)BattClockBase->SysIFace); } HostLib_Close(BattClockBase->Lib, NULL); } } return 0; }
static int bsdsocket_Init(struct bsdsocketBase *SocketBase) { APTR HostLibBase = OpenResource("hostlib.resource"); if (!HostLibBase) return FALSE; SocketBase->HostLibBase = HostLibBase; SocketBase->winsock = HostLib_Open("Ws2_32.dll", NULL); if (!SocketBase->winsock) return FALSE; SocketBase->resolver = HostLib_Open("Libs\\Host\\bsdsocket.dll", NULL); if (!SocketBase->resolver) return FALSE; SocketBase->WSIFace = (struct WinSockInterface *)HostLib_GetInterface(SocketBase->winsock, ws_functions, NULL); if (!SocketBase->WSIFace) { D(bug("[socket] Failed to obtain winsock interface\n")); return FALSE; } SocketBase->ResIFace = (struct HostSocketInterface *)HostLib_GetInterface(SocketBase->resolver, res_functions, NULL); if (!SocketBase->ResIFace) return FALSE; NewList((struct List *)&SocketBase->socks); Forbid(); SocketBase->ctl = SocketBase->ResIFace->sock_init(); Permit(); if (!SocketBase->ctl) return FALSE; return TRUE; }
/* auto init */ static int BattClock_Init(struct BattClockBase *BattClockBase) { APTR HostLibBase; ULONG r; HostLibBase = OpenResource("hostlib.resource"); D(bug("[battclock] HostLibBase = 0x%08lX\n", HostLibBase)); if (HostLibBase) { BattClockBase->Lib = HostLib_Open("kernel32.dll", NULL); if (BattClockBase->Lib) { BattClockBase->KernelIFace = (struct KernelInterface *)HostLib_GetInterface(BattClockBase->Lib, Symbols, &r); D(bug("[battclock] KernelIFace = 0x%08lX\n", BattClockBase->KernelIFace)); if (BattClockBase->KernelIFace) { if (!r) return 1; HostLib_DropInterface((APTR)BattClockBase->KernelIFace); } HostLib_Close(BattClockBase->Lib, NULL); } } return 0; }
APTR *gdi_hostlib_load_so(const char *sofile, const char **names, void **handle) { APTR *funcptr; ULONG i; D(bug("[gdi] loading functions from %s\n", sofile)); if ((*handle = HostLib_Open(sofile, NULL)) == NULL) { D(kprintf("[gdi] couldn't open '%s'\n", sofile)); return NULL; } funcptr = HostLib_GetInterface(*handle, names, &i); if (funcptr) { if (!i) { D(bug("[gdi] done\n")); return funcptr; } D(kprintf("[gdi] couldn't get %lu symbols from '%s'\n", i, sofile)); HostLib_DropInterface(funcptr); } HostLib_Close(*handle, NULL); return NULL; }