Имя пользователя:
Пароль:
 

Название темы: Перевести код с Delphi на С
Показать сообщение отдельно

Аватара для ferget

Разный


Сообщения: 1294
Благодарности: 359

Профиль | Отправить PM | Цитировать


Builer'а нету, поэтому сделал тестовую Dll в VS

DLL:

файл main.cpp

Код: Выделить весь код
#include <string.h>
#include "main.h"

const char*  PLUGIN_NAME="biss";
// a sample exported function
extern "C" __declspec(dllexport) void __stdcall On_Send_Dll_ID_Name(char* Name)
{
	strcpy(Name,PLUGIN_NAME);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
	switch (fdwReason)
	{
	case DLL_PROCESS_ATTACH:
		// attach to process
		// return FALSE to fail DLL load
		break;

	case DLL_PROCESS_DETACH:
		// detach from process
		break;

	case DLL_THREAD_ATTACH:
		// attach to thread
		break;

	case DLL_THREAD_DETACH:
		// detach from thread
		break;
	}
	return TRUE; // succesful
}
файл main.h

Код: Выделить весь код
#ifndef __MAIN_H__
#define __MAIN_H__

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus
extern "C"
{
#endif

__declspec(dllexport) void __stdcall On_Send_Dll_ID_Name(char* Name);

#ifdef __cplusplus
}
#endif

#endif // __MAIN_H__
для проверки

файл testDll.cpp

Код: Выделить весь код
#include <iostream>
#include "main.h"
using namespace std;

#pragma comment(lib,"Win32Project1")

int main()
{
	char* ls=new char[20];
	On_Send_Dll_ID_Name(ls);
	cout<<ls<<endl;
	delete[] ls;
	return 0;
}
выводит в консоль biss
Это сообщение посчитали полезным следующие участники:

Отправлено: 23:24, 26-08-2012 | #6

Название темы: Перевести код с Delphi на С