Code:
// wrapper around GetProcAddress
let dm = getProcAddress(moduleName: "USER32", procName: "DestroyMenu")
print("!!! getProcAddress: \(dm)")
withUnsafePointer(to: DestroyMenu) { ptr in
print("!!! withUnsafePointer(to:): \(ptr)")
ptr.withMemoryRebound(to: UnsafeRawPointer.self, capacity: 2) { ptr2 in
let bp = UnsafeBufferPointer(start: ptr2, count: 2)
print("!!! bp[0]: \(bp[0]) bp[1]: \(bp[1])")
}
}
Output:
!!! getProcAddress: Optional(0x00007fffbaac3d50)
!!! withUnsafePointer(to:): 0x000000b8f52ff4c8
!!! bp[0]: 0x00007ff65bce73e0 bp[1]: 0x00000230e02a0320
Is it possible to get DestroyMenu
address without GetProcAddress
?
What is DestroyMenu
really is? It doesn't look like pointer to C function. Next code doesn't combile because of __stdcall
convention I guess:
typealias DestroyMenuFunction = (@convention(c) (HMENU?) -> Bool)
let dmm: DestroyMenuFunction = DestroyMenu