mirror of
https://gitea.tendokyu.moe/Dniel97/segatools.git
synced 2024-11-30 23:57:15 +01:00
48 lines
892 B
C
48 lines
892 B
C
|
#include <windows.h>
|
||
|
|
||
|
#include <assert.h>
|
||
|
#include <stdint.h>
|
||
|
|
||
|
#include "util/dll-bind.h"
|
||
|
#include "util/dprintf.h"
|
||
|
|
||
|
HRESULT dll_bind(
|
||
|
void *dest,
|
||
|
HINSTANCE src,
|
||
|
const struct dll_bind_sym **syms_pos,
|
||
|
size_t syms_count)
|
||
|
{
|
||
|
HRESULT hr;
|
||
|
void *src_result;
|
||
|
void **dest_field;
|
||
|
const struct dll_bind_sym *current_sym;
|
||
|
size_t i;
|
||
|
|
||
|
assert(dest != NULL);
|
||
|
assert(src != NULL);
|
||
|
assert(syms_pos != NULL);
|
||
|
|
||
|
hr = S_OK;
|
||
|
current_sym = *syms_pos;
|
||
|
|
||
|
assert(current_sym != NULL);
|
||
|
|
||
|
for (i = 0; i < syms_count; i++) {
|
||
|
src_result = GetProcAddress(src, current_sym->sym);
|
||
|
|
||
|
if (src_result == NULL) {
|
||
|
hr = E_NOTIMPL;
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
dest_field = (void **)(((uint8_t *)dest) + current_sym->off);
|
||
|
*dest_field = src_result;
|
||
|
current_sym++;
|
||
|
}
|
||
|
|
||
|
*syms_pos = current_sym;
|
||
|
|
||
|
return hr;
|
||
|
}
|