下面的代码,cargo build时,提示:
29 | let url2 = windows::w!(url);
| ^^^ no rules expected this token in macro call
use std::net::TcpListener;
use windows::Win32::UI::WindowsAndMessaging::SW_SHOWNORMAL;
use windows::Win32::System::Console::FreeConsole;
use std::net::TcpStream;
use std::io::{Read, Write};
use windows::Win32::UI::Shell::ShellExecuteW;
fn main() {
// 监听端口7891的TCP连接
let listener = TcpListener::bind("127.0.0.1:7891").unwrap();
open_browser("http://127.0.0.1:7891");
// 调用FreeConsole关闭控制台窗口
unsafe {
FreeConsole();
}
// 启动web server
for stream in listener.incoming() {
let stream = stream.unwrap();
handle_client(stream);
}
}
#[cfg(windows)]
fn open_browser(url: &str) {
unsafe {
let url2 = windows::w!(url);
ShellExecuteW(None,
None,
url2.as_ptr(),
None,
None,
SW_SHOWNORMAL);
}
}
fn handle_client(mut stream: TcpStream) {
let mut buffer = [0; 1024];
stream.read(&mut buffer).unwrap();
// 返回HTTP响应
let response = "HTTP/1.1 200 OK\r\n\r\nHello, World!";
stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap();
}
1
共 5 条评论, 1 页
评论区
写评论这算什么bug呀,你用widestring库里的U16CString给str包一下,然后再用PCWSTR的from_raw,你可以参考下我这的这个
w!宏只支持literal
bug不bug不知道,但很难用
现在还处于步步皆BUG阶段