- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
WinHttpGetIEProxyConfigForCurrentUser 的文档说:
The caller must free the lpszProxy, lpszProxyBypass and lpszAutoConfigUrl strings in the WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure if they are non-NULL. Use GlobalFree to free the strings.
我编写了以下代码(Delphi 10.3.2):
var
VConfig: TWinHttpCurrentUserIEProxyConfig;
begin
FillChar(VConfig, SizeOf(VConfig), 0);
if not WinHttpGetIEProxyConfigForCurrentUser(VConfig) then begin
RaiseLastOSError;
end;
...
if VConfig.lpszAutoConfigUrl <> nil then begin
GlobalFree(VConfig.lpszAutoConfigUrl); // <-- Error
end;
并出现错误:
[dcc32 Error] E2010 Incompatible types: 'NativeUInt' and 'PWideChar'
问题:
我应该将 PWideChar
类型转换为 NativeUInt
吗?
我可以使用 GlobafFreePtr
代替 GlobafFree
(它接受 PWideChar
并且在我的测试中工作正常)?
最佳答案
当 MSDN 告诉您免费使用特定功能时,那么这样做就是您最好的选择。
Windows API 的部分内容是用 C 语言编写的(有些部分甚至没有定义 STRICT
?),而具有更好类型检查的其他语言在某些地方将需要强制转换。
对于 HGLOBAL,您可以使用 GlobalFlags
函数来帮助您。在您的情况下,标志的低字节为零,表示没有锁。如果字符串已被分配为可移动,则文档必须告诉您在访问内存之前锁定,但事实并非如此。
棺材上的最后一颗钉子是调试该函数,如果您这样做,您将看到它调用 GlobalAlloc
并将标志设置为 0x40 (GPTR
),并且应该因此无需解锁即可传递给 GlobalFree。如果您的编译器提示,那么您必须转换为适当的类型:
GlobalFree(HGLOBAL(VConfig.lpszAutoConfigUrl));
关于delphi - GlobalFree - 不兼容的类型 : 'NativeUInt' and 'PWideChar' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58707564/
我知道这可能很简单,但有时 Unicode 问题会因为太多的考虑而困扰我。 我有这个代码: pcBuffer := StrAlloc(Stream.Size + 1) where pcBuffer i
我刚刚遇到了一个奇怪的问题。我正在尝试将模型加载到 OpenGL,并在加载纹理的部分使用 auxDIBImageLoadA(dibfile:PWideChar)功能。这是我的代码调用它 procedu
这个问题已经有答案了: What is the difference between WideChar and AnsiChar? (2 个回答) 已关闭 8 年前。 我是delphi XE8的新手。
通过 Windows API 调用 ( GetUserPreferredUILanguages() ),我得到一个以 one null 分隔的 PWideChar 形式的字符串列表。我需要将其转换为
我经常读到编译器在转换为 PChar 时会产生某种魔力。 . PChar的主要目的|是在期望零终止字符数组(C 风格的“字符串”)的库中调用外部代码。 PChar是 PWideChar 的别名类型关于
WinHttpGetIEProxyConfigForCurrentUser 的文档说: The caller must free the lpszProxy, lpszProxyBypass and
因此,我尝试在 ShellExecute 中使用变量,但在编译时总是出现此错误[DCC Error] Unit1.pas(44): E2010 不兼容类型:'string' 和 'PWideChar'
我使用 libxml2 ( http://www.xmlsoft.org/ ) 在我的 Delphi 代码中读取/写入 xml 文件。 libxml2 对所有字符串使用 UTF-8 编码。 例如,函数
我正在使用delphi-xe3中的Windows API从这里实现Ping功能(http://delphi.about.com/od/internetintranet/l/aa081503a.htm)
我在我的主可执行文件上为几个 PWideChar 分配内存 var pwcValor: PWideChar; begin pwcValor := AllocMem( sizeof(WideCh
我有一段来自 Delphi 7 的代码: var lpRgnData: PRgnData; PC: PChar; PR: PRect; ... PC := @(lpRgnData
我尝试使用 winrar 命令行压缩文件,但是当我在命令行中添加变量时,我收到这些错误类型“PWideChar”和“字符串”不兼容! 我将 sdate 变量转换为 WideChar 但它不起作用!!
如何使用 Delphi 在 Android 平台上将字符串转换为 PwideChar?在 Windows 应用程序中,它已完成使用.. var PW: PWideChar; begin
我是一名优秀的程序员,十分优秀!