本文整理汇总了C++中Handle_val函数的典型用法代码示例。如果您正苦于以下问题:C++ Handle_val函数的具体用法?C++ Handle_val怎么用?C++ Handle_val使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Handle_val函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copy_file_times
// Copy file times
CAMLprim value copy_file_times(value in_h_val, value out_h_val) {
CAMLparam2(in_h_val, out_h_val);
int good;
#if defined(WIN32)
HANDLE in_h = Handle_val(in_h_val);
HANDLE out_h = Handle_val(out_h_val);
FILETIME create;
FILETIME access;
FILETIME modify;
good = GetFileTime(in_h, &create, &access, &modify);
if(good) {
good = SetFileTime(out_h, &create, &access, &modify);
}
#else
int in_h = Int_val(in_h_val);
int out_h = Int_val(out_h_val);
struct stat s;
struct timeval set[2];
good = !fstat(in_h, &s);
if(good) {
set[0].tv_sec = s.st_atime;
set[0].tv_usec = 0;
set[1].tv_sec = s.st_mtime;
set[1].tv_usec = 0;
good = !futimes(out_h, set);
}
#endif
CAMLreturn(Val_bool(good));
}
示例2: caml_dynlink_lookup_symbol
/*#include <stdio.h>*/
CAMLprim value caml_dynlink_lookup_symbol(value handle, value symbolname)
{
void * symb;
value result;
symb = caml_dlsym(Handle_val(handle), String_val(symbolname));
/* printf("%s = 0x%lx\n", String_val(symbolname), symb);
fflush(stdout); */
if (symb == NULL) return Val_unit /*caml_failwith(caml_dlerror())*/;
result = caml_alloc_small(1, Abstract_tag);
Handle_val(result) = symb;
return result;
}
示例3: CAMLparam5
CAMLprim value w_create_process_native
(value prog, value wprog, value wargs, value fd1, value fd2, value fd3)
{
int res, flags;
PROCESS_INFORMATION pi;
STARTUPINFOW si;
wchar_t fullname [MAX_PATH];
HANDLE h;
CAMLparam5(wprog, wargs, fd1, fd2, fd3);
res = SearchPathW (NULL, (LPCWSTR) String_val(wprog), L".exe",
MAX_PATH, fullname, NULL);
if (res == 0) {
win32_maperr (GetLastError ());
uerror("create_process", prog);
}
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = Handle_val(fd1);
si.hStdOutput = Handle_val(fd2);
si.hStdError = Handle_val(fd3);
flags = GetPriorityClass (GetCurrentProcess ());
/*
h = CreateFile ("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h != INVALID_HANDLE_VALUE)
CloseHandle (h);
else {
flags |= CREATE_NEW_CONSOLE;
// si.dwFlags |= STARTF_USESHOWWINDOW;
// si.wShowWindow = SW_MINIMIZE;
}
*/
res = CreateProcessW (fullname, (LPWSTR) String_val(wargs),
NULL, NULL, TRUE, flags,
NULL, NULL, &si, &pi);
if (res == 0) {
win32_maperr (GetLastError ());
uerror("create_process", prog);
}
CloseHandle (pi.hThread);
CAMLreturn (Val_long (pi.hProcess));
}
示例4: win_set_inherit
int win_set_inherit(value fd, BOOL inherit)
{
HANDLE oldh, newh;
oldh = Handle_val(fd);
if (! DuplicateHandle(GetCurrentProcess(), oldh,
GetCurrentProcess(), &newh,
0L, inherit, DUPLICATE_SAME_ACCESS)) {
win32_maperr(GetLastError());
return -1;
}
Handle_val(fd) = newh;
CloseHandle(oldh);
return 0;
}
示例5: lwt_unix_read
CAMLprim value lwt_unix_read(value fd, value buf, value vofs, value vlen)
{
intnat ofs, len, written;
DWORD numbytes, numwritten;
DWORD err = 0;
Begin_root (buf);
ofs = Long_val(vofs);
len = Long_val(vlen);
written = 0;
if (len > 0) {
numbytes = len;
if (Descr_kind_val(fd) == KIND_SOCKET) {
int ret;
SOCKET s = Socket_val(fd);
ret = recv(s, &Byte(buf, ofs), numbytes, 0);
if (ret == SOCKET_ERROR) err = WSAGetLastError();
numwritten = ret;
} else {
HANDLE h = Handle_val(fd);
if (! ReadFile(h, &Byte(buf, ofs), numbytes, &numwritten, NULL))
err = GetLastError();
}
if (err) {
win32_maperr(err);
uerror("write", Nothing);
}
written = numwritten;
}
End_roots();
return Val_long(written);
}
示例6: handle_of_descr
static HANDLE handle_of_descr(value x)
{
if(Descr_kind_val(x) != KIND_HANDLE){
failwith("mlterminal(the channel is not a file handle)");
}
return Handle_val(x);
}
示例7: unix_read
CAMLprim value unix_read(value fd, value buf, value ofs, value vlen)
{
intnat len;
DWORD numbytes, numread;
char iobuf[UNIX_BUFFER_SIZE];
DWORD err = 0;
Begin_root (buf);
len = Long_val(vlen);
numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len;
if (Descr_kind_val(fd) == KIND_SOCKET) {
int ret;
SOCKET s = Socket_val(fd);
enter_blocking_section();
ret = recv(s, iobuf, numbytes, 0);
if (ret == SOCKET_ERROR) err = WSAGetLastError();
leave_blocking_section();
numread = ret;
} else {
HANDLE h = Handle_val(fd);
enter_blocking_section();
if (! ReadFile(h, iobuf, numbytes, &numread, NULL))
err = GetLastError();
leave_blocking_section();
}
if (err) {
win32_maperr(err);
uerror("read", Nothing);
}
memmove (&Byte(buf, Long_val(ofs)), iobuf, numread);
End_roots();
return Val_int(numread);
}
示例8: onlyWin32_create_process_chdir_native
value onlyWin32_create_process_chdir_native(value cmd, value cmdline, value env,
value fd1, value fd2, value fd3, value maybe_chdir)
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
char * exefile, * envp;
int flags;
LPCTSTR lpCurrentDirectory = NULL;
exefile = search_exe_in_path(String_val(cmd));
if (env != Val_int(0)) {
envp = String_val(Field(env, 0));
} else {
envp = NULL;
}
/* Prepare stdin/stdout/stderr redirection */
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = Handle_val(fd1);
si.hStdOutput = Handle_val(fd2);
si.hStdError = Handle_val(fd3);
/* If we do not have a console window, then we must create one
before running the process (keep it hidden for apparence).
If we are starting a GUI application, the newly created
console should not matter. */
if (onlyWin32_has_console())
flags = 0;
else {
flags = CREATE_NEW_CONSOLE;
si.dwFlags = (STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES);
si.wShowWindow = SW_HIDE;
}
if( maybe_chdir != Val_int(0) ){
lpCurrentDirectory = String_val(Field(maybe_chdir,0));
}
/* Create the process */
if (! CreateProcess(NULL, String_val(cmdline), NULL, NULL,
TRUE, flags, envp, lpCurrentDirectory, &si, &pi)) {
win32_maperr(GetLastError());
uerror("create_process", cmd);
}
CloseHandle(pi.hThread);
/* Return the process handle as pseudo-PID
(this is consistent with the wait() emulation in the MSVC C library */
return Val_long(pi.hProcess);
}
示例9: win_alloc_handle
value win_alloc_handle(HANDLE h)
{
value res = alloc_custom(&win_handle_ops, sizeof(struct filedescr), 0, 1);
Handle_val(res) = h;
Descr_kind_val(res) = KIND_HANDLE;
CRT_fd_val(res) = NO_CRT_FD;
return res;
}
示例10: win_findclose
CAMLprim value win_findclose(value valh)
{
if (! FindClose(Handle_val(valh))) {
win32_maperr(GetLastError());
uerror("closedir", Nothing);
}
return Val_unit;
}
示例11: unix_lseek_64
CAMLprim value unix_lseek_64(value fd, value ofs, value cmd)
{
__int64 ret;
ret = caml_set_file_pointer(Handle_val(fd), Int64_val(ofs),
seek_command_table[Int_val(cmd)]);
return copy_int64(ret);
}
示例12: do_fstat
static value do_fstat(value handle, int use_64)
{
int ret;
struct _stat64 buf;
__int64 st_ino;
HANDLE h;
DWORD ft;
st_ino = 0;
memset(&buf, 0, sizeof buf);
buf.st_nlink = 1;
h = Handle_val(handle);
ft = GetFileType(h) & ~FILE_TYPE_REMOTE;
switch(ft) {
case FILE_TYPE_DISK:
if (!safe_do_stat(0, use_64, NULL, Handle_val(handle), &st_ino, &buf)) {
uerror("fstat", Nothing);
}
break;
case FILE_TYPE_CHAR:
buf.st_mode = S_IFCHR;
break;
case FILE_TYPE_PIPE:
{
DWORD n_avail;
if (Descr_kind_val(handle) == KIND_SOCKET) {
buf.st_mode = S_IFSOCK;
}
else {
buf.st_mode = S_IFIFO;
}
if (PeekNamedPipe(h, NULL, 0, NULL, &n_avail, NULL)) {
buf.st_size = n_avail;
}
}
break;
case FILE_TYPE_UNKNOWN:
unix_error(EBADF, "fstat", Nothing);
default:
win32_maperr(GetLastError());
uerror("fstat", Nothing);
}
return stat_aux(use_64, st_ino, &buf);
}
示例13: win_findclosew
CAMLprim value win_findclosew(value valh)
{
CAMLparam1(valh);
if (! FindClose(Handle_val(valh))) {
win32_maperr(GetLastError());
uerror("closedir", Nothing);
}
CAMLreturn (Val_unit);
}
示例14: win_CRT_fd_of_filedescr
int win_CRT_fd_of_filedescr(value handle)
{
if (CRT_fd_val(handle) != NO_CRT_FD) {
return CRT_fd_val(handle);
} else {
int fd = _open_osfhandle((long) Handle_val(handle), O_BINARY);
if (fd == -1) uerror("channel_of_descr", Nothing);
return fd;
}
}
示例15: unix_fstat_64
CAMLprim value unix_fstat_64(value handle)
{
int ret;
struct _stat64 buf;
__int64 st_ino;
if (!do_stat(0, 1, NULL, 0, Handle_val(handle), &st_ino, &buf)) {
uerror("fstat", Nothing);
}
return stat_aux(1, st_ino, &buf);
}