pubspec.yaml 에 다음과 같이 js 패키지를 추가합니다.
Copy dependencies:
flutter:
sdk: flutter
ffi: ^2.0.1
charset_converter: ^2.0.1
cupertino_icons: ^1.0.6
intl: ^0.18.0
dev_dependencies:
flutter_test:
sdk: flutter
ffi: ^2.0.1
charset_converter: ^2.0.1
flutter_lints: ^3.0.0
intl: ^0.18.0
추가하고 패키지를 설치합니다.
Copy import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
import 'package:ffi/ffi.dart';
import 'dart:typed_data';
import 'package:charset_converter/charset_converter.dart';
// DLL 파일 로드
final DynamicLibrary PosPayLibrary = DynamicLibrary.open('PayDll_x64.dll');
typedef CEasyPay = Int32 Function(
Pointer<Utf8> sIp, Int32 iPort,
Pointer<Utf8> sGd,
Pointer<Utf8> sSend, Int32 iSendLn,
Pointer<Utf8> sSignGubun,
Pointer<Utf8> sSignPath, Int32 iSignPathLn,
Pointer<Utf8> sRecv);
typedef DartEasyPay = int Function(
Pointer<Utf8> sIp, int iPort,
Pointer<Utf8> sGd,
Pointer<Utf8> sSend, int iSendLn,
Pointer<Utf8> sSGubun,
Pointer<Utf8> sPath, int iPathLn,
Pointer<Utf8> sRecv);
final EasyPay = PosPayLibrary
.lookupFunction<CEasyPay, DartEasyPay>('EasyPay');
Copy //Dll 호출
String ip, gd, send, sGubun, sPath;
Pointer<Utf8> sIp = ip.toNativeUtf8();
Pointer<Utf8> sGd = gd.toNativeUtf8();
Pointer<Utf8> sSend = send.toNativeUtf8();
Pointer<Utf8> sGubun = sGubun.toNativeUtf8();
Pointer<Utf8> sPath = sPath.toNativeUtf8();
Pointer<Uint8> sRecv = calloc<Uint8>(1024);
int result = EasyPay(sIp, port, sGd, sSend, send.length, sSGubun,
sPath, sPath.length, sRecv.cast<Utf8>());
Copy Future<String> extractString(int length) async {
if (offset + length > recvData.length) {
print("Error: Buffer Overflow Detected");
return "";
}
Uint8List bytes = recvData.sublist(offset, offset + length);
offset += length;
String result = await CharsetConverter.decode("euc-kr", bytes);
return result.trim();
}
Copy // run
flutter run -d windows
Launching lib\main.dart on Windows in debug mode...
Building Windows application... 8.6s
✓ Built build\windows\x64\runner\Debug\my_flutter_app.exe
Syncing files to device Windows... 54ms
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
A Dart VM Service on Windows is available at: http://127.0.0.1:53106/JNRgyWRPPeI=/
정상적으로 한글 처리가 되었습니다.