При попытках вида:
[DllImport(fileDLL)]
public static Main_struct main_struct;
компилятор выдает ошибку: Аttribute 'DllImport' is not valid on this declaration type. It is only valid on 'method' declarations.
В этой статье показано как использовать функцию из dll, в которую передается структура.
Мне надо получить доступ к статической структуре из dll (в которой есть указатели на функции).
Re: C#: Как получить доступ к static struct из C++ dll
Насколько я понимаю указатель на экспортированую структуру можно получить через обычный GetProcAddress, так что LoadLibrary + GetProcAddress + Marshal.PtrToStructure.
Re: C#: Как получить доступ к static struct из C++ dll
This simply returns an IntPtr to an area of the global heap that contains a copy of the data. The only problem with this function is that you have to remember to release the allocated heap memory after use. For example:
…works exactly like default marshalling. But don’t forget that lpstruct is itself still being marshalled as a pass-by-value integer. To copy the result back to the struct an additional function is required:
Здравствуйте, newalex77, Вы писали:
N>Есть с++ dll, в которой объявлена статическая структура вида:
N> typedef int (*reset)(void *context);
N> typedef int (*update)(void *context, const uint8_t *data, size_t length);
N> typedef int (*finalize)(void *context,uint8_t *digest);
N> typedef struct N> { N> reset reset; N> update update; N> finalize finalize; N> size_t context_size; N> size_t block_size; N> size_t digest_si N>} main_struct;
N>Как получить доступ к main_struct из C# ?
N>При попытках вида: N> [DllImport(fileDLL)] N> public static Main_struct main_struct; N>компилятор выдает ошибку: Аttribute 'DllImport' is not valid on this declaration type. It is only valid on 'method' declarations.
До структуры ты не достучишься, можно только запустить метод или функцию, структуры придется объявлять самому
Re: C#: Как получить доступ к static struct из C++ dll
Здравствуйте, newalex77, Вы писали:
N>Есть с++ dll, в которой объявлена статическая структура вида:
N> typedef int (*reset)(void *context);
N> typedef int (*update)(void *context, const uint8_t *data, size_t length);
N> typedef int (*finalize)(void *context,uint8_t *digest);
N> typedef struct N> { N> reset reset; N> update update; N> finalize finalize; N> size_t context_size; N> size_t block_size; N> size_t digest_si N>} main_struct;
N>Как получить доступ к main_struct из C# ?
N>При попытках вида: N> [DllImport(fileDLL)] N> public static Main_struct main_struct; N>компилятор выдает ошибку: Аttribute 'DllImport' is not valid on this declaration type. It is only valid on 'method' declarations.
Структуры придется объявлять самому в C#, чем я сейчас и занимаюсь. Из DLL доступны методы и функции