无法找到区域设置感知版本的StrSafe函数(StringCbPrintf_lW)(Locale-aware version of StrSafe function (StringCbPrintf_lW) cannot be found)
我们(错误地)使用StringCbPrintfW来编写数据库查询,该查询在使用逗号作为小数分隔符的任何语言环境中都失败了。 修复很容易,对吧? 采用语言环境的StringCbPrintf_lW也在strsafe.h中定义。 两者都定义如下:
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
所以只需创建语言环境并用StringCbPrintf_lW替换StringCbPrintfW。
Intellisense很高兴,GoToDefinition很高兴,ClCompile不高兴。 我一直在
错误C3861:'StringCbPrintf_lW':找不到标识符
有什么想法有什么不对?
We (mistakenly) used StringCbPrintfW to write a database query which failed miserably on any locale that uses a comma as the decimal separator. Fix is easy enough, right? StringCbPrintf_lW, which takes a locale, is also defined in strsafe.h. Both are defined under:
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
so just create the locale and replace StringCbPrintfW with StringCbPrintf_lW.
Intellisense is happy, GoToDefinition is happy, ClCompile is not. I keep getting
error C3861: 'StringCbPrintf_lW': identifier not found
Any ideas what is wrong?
原文:https://stackoverflow.com/questions/37440682
最满意答案
没有任何地方宣布这一点,我认为这是搞砸我的原因。
等等,它在那里声明 - 在方法的标题中:
static double GetDouble(string prompt) // ^^^^^^^^^^^^^ This is the declaration of prompt
prompt
与您看到的其他变量不同,它不是正常变量:它是方法的形式参数 。与使用赋值运算符
=
初始化和明确赋值的常规变量不同,通过调用方法隐式赋值形式参数。 当您调用该方法时,您将向其传递一个带有实际参数的表达式,该参数用作该表达式到形式参数的赋值。 想象一下,在第一次调用之前,将prompt
变量分配为"Enter the base: "
,然后在第二次调用之前为其指定"enter the exponent: "
以了解调用GetDouble
。Nowhere is this declared and I think that's what's messing me up.
Wait, it's declared right there - in the header of the method:
static double GetDouble(string prompt) // ^^^^^^^^^^^^^ This is the declaration of prompt
prompt
is different from other variables that you have seen in that it is not a normal variable: it is a formal parameter of a method.Unlike regular variables which you initialize and assign explicitly with the assignment operator
=
, formal parameters are assigned implicitly by virtue of calling a method. When you call the method, you pass it an expression with the actual parameter, which acts as an assignment of that expression to the formal parameter. Imagine that theprompt
variable is assigned"Enter the base: "
before the first call, and then it is assigned"enter the exponent: "
before the second call to understand what is going on when you callGetDouble
.
相关问答
更多-
正确处理异常:“getParameters失败(空参数)”(Correct handling of exception: “getParameters failed (empty parameters)”)[2023-09-25]
在我的情况下,我得到这个错误: getParameters失败(空参数) 当我解锁相机后调用getParameters() 。 所以,请在调用camera.unlock()之前调用getParameters() camera.unlock() 。 As +Eddy Talvala mentioned, this happens when the camera is in a bad state. How does the camera get in a bad state? 1) Probably the ... -
这是一个非常全面的指导,我认为是必读: 异常和错误处理 - C ++常见问题或C ++常见问题 作为一般的经验法则,当您的程序可以识别出阻止执行的外部问题时,抛出异常。 如果您从服务器接收数据,并且数据无效,则抛出异常。 磁盘空间不足? 抛出异常 宇宙射线阻止您查询数据库? 抛出异常 但是如果您从自己的程序中获取一些无效数据 - 不要抛出异常。 如果你的问题来自你自己的坏代码,最好使用ASSERT来防范它。 需要异常处理来识别程序无法处理的问题,并告诉他们有关用户的问题,因为用户可以处理它们。 但程序中的错 ...
-
只需检查File.Exists。 如果没有文件,则将该参数设置为DbNull.Value,否则读取该文件 Dim exists = File.Exists(OpenFileDialog8.FileName) ..... cmd.Parameters.Add(New SqlClient.SqlParameter( _ "@AnyOtherDocument", SqlDbType.Image)).Value _ = If(exists, IO.File.ReadAllBytes(Open ...
-
总之......不。 出于某些原因,请参阅捕获方法状态的问题。 In short ... no. See this question on capturing method state for some reasons.
-
Java异常处理方法(Java exception handling method)[2023-09-02]
总的想法是,你将例外渗透到适当的地方来处理它们。 我猜你的导师希望他们能够主要处理。 在这种情况下,我可以猜测,因为你给出了throws子句。 一个简单的经验法则是,如果该方法在throws子句中声明了异常,则不会在该方法中捕获该异常。 所以你写的方法应该没有catch语句。 要做到这一点,你需要改变你的代码: public Catalog loadCatalog(String filename) throws FileNotFoundException, IOExcept ... -
异常消息处理(Exception Message Handling)[2022-08-08]
根据您所编写的内容,Logic会抛出SpecificException但某些特定信息可能仅在Main可用(如果您有不同的主电源,则可能在语义上不同,即它们可能取决于上下文)。 因此,似乎合理的是, SpecificException仅提供可由Logic提供的上下文信息,然后在Main您可以拥有一个使用SpecificException和特定信息来构建用户消息和(如果需要)日志的辅助类(在文件上,db,等一些可以在以后用于统计或类似事情的信息。 辅助类可以管理不同的Main / SpecificInforma ... -
DAL中的异常处理(Exception handling in DAL)[2022-01-30]
您返回false表示存在异常。 不建议这样做。 重新抛出它 catch(Exception e) { //blah, maybe add some useful text to e throw; } finally { //close up shop Although, look up what using does first incidentally } 然后处理它( catch (Exception e) { MessageBox.Show(("Error: " + e.Message)) ... -
没有任何地方宣布这一点,我认为这是搞砸我的原因。 等等,它在那里声明 - 在方法的标题中: static double GetDouble(string prompt) // ^^^^^^^^^^^^^ This is the declaration of prompt prompt与您看到的其他变量不同,它不是正常变量:它是方法的形式参数 。 与使用赋值运算符=初始化和明确赋值的常规变量不同,通过调用方法隐式赋值形式参数。 当您调用该方法时,您将向其传递一个带有 ...
-
我个人不会在finally添加一个try catch块,然后它可以是一个无穷无尽的链。 通常你不应该在finally有复杂的东西,并且在任何情况下都应该在调用者中捕获意外的异常。 编辑:看起来更接近代码,我不明白为什么最终的代码不应该在try块中。 I personally wouldn't add a try catch block in the finally, then it can be an endless chain. Usually you shouldn't have complicated ...
-
帮助处理异常(Help with Exception handling)[2022-11-13]
不要尝试捕获每个方法或层,只有它是合理的。 尝试捕获永远不应该像有条件的那样。 表示层应该永远不会有逻辑。 由于您使用DAL接口,我将创建一个自定义DalException并将其抛出SQLException public int addMethod(ContactClass contactObj) throws DalException { try { return ExecuteSomeSP("SPName", SP_Parameters); } catch(SQL ...