|
|
@ -2,14 +2,10 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
dde "go-dde/ddeml"
|
|
|
|
"go-dde/dde"
|
|
|
|
|
|
|
|
"go-dde/ddeml"
|
|
|
|
. "go-dde/types"
|
|
|
|
. "go-dde/types"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
|
|
MAX_BUFFER_SIZE = 16
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func DdeCallback(wType int, wFmt int, hConv uintptr, hsz1 uintptr, hsz2 uintptr, hData uintptr, dwData1 int64, dwData2 int64) int {
|
|
|
|
func DdeCallback(wType int, wFmt int, hConv uintptr, hsz1 uintptr, hsz2 uintptr, hData uintptr, dwData1 int64, dwData2 int64) int {
|
|
|
@ -44,28 +40,6 @@ var callbacks FNCALLBACK = func(
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func DDERequest(idInst DWORD, hConv HCONV, hszItem HSZ, sDesc string) string {
|
|
|
|
|
|
|
|
hData := dde.DdeClientTransaction(nil, 0, hConv, hszItem, UINT(CF_TEXT),
|
|
|
|
|
|
|
|
UINT(XTYP_REQUEST), 5000, nil)
|
|
|
|
|
|
|
|
if hData == 0 {
|
|
|
|
|
|
|
|
return "Request failed"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
size := dde.DdeGetData(hData, nil, 0, 0)
|
|
|
|
|
|
|
|
var str BYTE
|
|
|
|
|
|
|
|
dde.DdeGetData(hData, &str, size, 0)
|
|
|
|
|
|
|
|
buffer := (*[MAX_BUFFER_SIZE]byte)(unsafe.Pointer(&str))[:size-1]
|
|
|
|
|
|
|
|
//szResult := *(*[]byte)(unsafe.Pointer(&str))
|
|
|
|
|
|
|
|
return string(buffer)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func DDEPoke(idInst DWORD, hConv HCONV, hszItem HSZ, szData string) {
|
|
|
|
|
|
|
|
var data []byte = []byte(szData)
|
|
|
|
|
|
|
|
dde.DdeClientTransaction((unsafe.Pointer(&data)),
|
|
|
|
|
|
|
|
DWORD(len(data)+1),
|
|
|
|
|
|
|
|
hConv, hszItem, UINT(CF_TEXT),
|
|
|
|
|
|
|
|
UINT(XTYP_POKE), 3000, nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var idInst DWORD = 0
|
|
|
|
var idInst DWORD = 0
|
|
|
|
var szApp VString = "Server"
|
|
|
|
var szApp VString = "Server"
|
|
|
|
var szTopic VString = "MyTopic"
|
|
|
|
var szTopic VString = "MyTopic"
|
|
|
@ -73,12 +47,9 @@ var items []VString = []VString{"MyItem0", "MyItem1", "MyItem2", "MyItem3", "MyI
|
|
|
|
var hszItem []HSZ = make([]HSZ, len(items))
|
|
|
|
var hszItem []HSZ = make([]HSZ, len(items))
|
|
|
|
|
|
|
|
|
|
|
|
func runClient() {
|
|
|
|
func runClient() {
|
|
|
|
// AddApis(dde.DdeApis)
|
|
|
|
|
|
|
|
// AddApis(dde.DdeANSIApis)
|
|
|
|
|
|
|
|
// AddApis(dde.DdeUnicodeApis)
|
|
|
|
|
|
|
|
var cmd DWORD = DWORD(APPCLASS_STANDARD | APPCMD_CLIENTONLY)
|
|
|
|
var cmd DWORD = DWORD(APPCLASS_STANDARD | APPCMD_CLIENTONLY)
|
|
|
|
var res DWORD = 0
|
|
|
|
var res DWORD = 0
|
|
|
|
iReturn := dde.DdeInitialize(&idInst, DdeCallback, cmd, res)
|
|
|
|
iReturn := ddeml.DdeInitialize(&idInst, DdeCallback, cmd, res)
|
|
|
|
if iReturn != UINT(DMLERR_NO_ERROR) {
|
|
|
|
if iReturn != UINT(DMLERR_NO_ERROR) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -86,28 +57,28 @@ func runClient() {
|
|
|
|
fmt.Printf("DDE Initialization Failed")
|
|
|
|
fmt.Printf("DDE Initialization Failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var hConv HCONV // 会话句柄
|
|
|
|
var hConv HCONV // 会话句柄
|
|
|
|
hszApp := dde.DdeCreateStringHandle(idInst, szApp, 0)
|
|
|
|
hszApp := ddeml.DdeCreateStringHandle(idInst, szApp, 0)
|
|
|
|
hszTopic := dde.DdeCreateStringHandle(idInst, szTopic, 0)
|
|
|
|
hszTopic := ddeml.DdeCreateStringHandle(idInst, szTopic, 0)
|
|
|
|
for i := 0; i < len(items); i++ {
|
|
|
|
for i := 0; i < len(items); i++ {
|
|
|
|
hszItem[i] = dde.DdeCreateStringHandle(idInst, items[i], 0)
|
|
|
|
hszItem[i] = ddeml.DdeCreateStringHandle(idInst, items[i], 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hConv = dde.DdeConnect(idInst, hszApp, hszTopic, nil)
|
|
|
|
hConv = ddeml.DdeConnect(idInst, hszApp, hszTopic, nil)
|
|
|
|
dde.DdeFreeStringHandle(idInst, hszApp)
|
|
|
|
ddeml.DdeFreeStringHandle(idInst, hszApp)
|
|
|
|
dde.DdeFreeStringHandle(idInst, hszTopic)
|
|
|
|
ddeml.DdeFreeStringHandle(idInst, hszTopic)
|
|
|
|
if hConv == 0 {
|
|
|
|
if hConv == 0 {
|
|
|
|
fmt.Printf("DDE Connection Failed.\n")
|
|
|
|
fmt.Printf("DDE Connection Failed.\n")
|
|
|
|
time.Sleep(2e9) //2e9 相当于2秒
|
|
|
|
time.Sleep(2e9) //2e9 相当于2秒
|
|
|
|
dde.DdeUninitialize(idInst)
|
|
|
|
ddeml.DdeUninitialize(idInst)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := 0; i < len(items); i++ {
|
|
|
|
for i := 0; i < len(items); i++ {
|
|
|
|
data := DDERequest(idInst, hConv, hszItem[i], "请求到服务端数据: ")
|
|
|
|
data := dde.DDERequest(idInst, hConv, hszItem[i], "请求到服务端数据: ")
|
|
|
|
fmt.Printf("data: %v\n", data)
|
|
|
|
fmt.Printf("data: %v\n", data)
|
|
|
|
DDEPoke(idInst, hConv, hszItem[i], data)
|
|
|
|
dde.DDEPoke(idInst, hConv, hszItem[i], data)
|
|
|
|
time.Sleep(1e9)
|
|
|
|
time.Sleep(1e9)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Printf("客户端关闭")
|
|
|
|
fmt.Printf("客户端关闭")
|
|
|
|
dde.DdeDisconnect(hConv)
|
|
|
|
ddeml.DdeDisconnect(hConv)
|
|
|
|
dde.DdeUninitialize(idInst)
|
|
|
|
ddeml.DdeUninitialize(idInst)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|