GVKun编程网logo

GetTempPathA 我如何提前知道尺寸? 返回值(getsizeof返回)

3

本文将为您提供关于GetTempPathA我如何提前知道尺寸?返回值的详细介绍,我们还将为您解释getsizeof返回的相关知识,同时,我们还将为您提供关于Anerrorhappenedduringt

本文将为您提供关于GetTempPathA 我如何提前知道尺寸? 返回值的详细介绍,我们还将为您解释getsizeof返回的相关知识,同时,我们还将为您提供关于An error happened during template parsing (template: "class path resource [templates/index.h...、An error happened during template parsing (template: "class path resource [templates/user.html]、attempted relative import with no known parent package、c# – GetCustomAttributes不返回值的实用信息。

本文目录一览:

GetTempPathA 我如何提前知道尺寸? 返回值(getsizeof返回)

GetTempPathA 我如何提前知道尺寸? 返回值(getsizeof返回)

如何解决GetTempPathA 我如何提前知道尺寸? 返回值?

我正在使用 Windows API 使用 C 语言编写代码。

我查看了 GetTempPathA() 函数 here,并在下面包含了该函数的语法。

DWORD GetTempPathA(
  DWORD nBufferLength,LPSTR lpBuffer
);

我可以看到路径将存储在 lpBuffer 中,但我不明白我如何期望知道将 DWORD nBufferLength 设置为多大 - 我希望具有更多 Windows 开发经验的人会告诉我这是一个值ANSI 语言系统和另一个用于 Unicode,但我更愿意向 Stackoverflow 上的专业人士寻求指导?

我认为它需要设置为文件路径的最长可能值,因为也许用户以某种方式将默认位置更改为系统其他地方的更长路径,但我只是猜测。

这似乎只是一个 ANSI 函数,但是在我查看 MSDN 上的文档期间,我经常发现具有 ANSI 和 Unicode 函数(分别以 A 和 W 结尾)的函数。我确实理解它们之间的区别,但是如果我必须创建一个缓冲区,最大输入大小是多少?

最后,在回答时请记住,我确实喜欢编写向后兼容的应用程序,因为我的许多朋友住在第三世界国家,无法使用最新的 Windows 操作系统。

解决方法

您可以使用固定大小缓冲区来容纳最大可能的路径长度(例如char buffer[MAX_PATH+1];),或者,如果您想分配刚好 > 缓冲区空间,最初调用 GetTempPathA 函数时,nBufferLength 参数为零,NULLlpBuffer 值。 (据我所知,后者没有完全记录,但下面的代码有效,并且该系统用于许多其他需要给定大小的缓冲区的 WinAPI 调用。)

测试代码:

#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    DWORD answer = GetTempPathA(0,NULL);
    printf("%lu\n",answer);
    char* buffer = malloc(answer);
    answer = GetTempPathA(answer,buffer);
    printf("Temp path is: >>>%s<<< (length = %lu)\n",buffer,answer);
    free(buffer);
    return 0;
}

请注意,第一个调用中 answer 的值将比第二个调用中的值大一个(因为前者将包含 nul 终止符的空间)。

来自documentation:

返回值

如果函数成功,则返回值是复制到lpBuffer的字符串的长度,以TCHARs为单位,不包括 终止空字符。如果返回值大于 nBufferLength,返回值是长度,以 TCHARs 为单位, 保存路径所需的缓冲区。

或者,对于“通用”版本,对于 Unicode 和多字节 (ANSI) 构建,请使用以下内容:

#include <Windows.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    DWORD answer = GetTempPath(0,NULL);
    _tprintf(TEXT("%lu\n"),answer);
    TCHAR* buffer = malloc(sizeof(TCHAR) * answer);
    answer = GetTempPath(answer,buffer);
    _tprintf(TEXT("Temp path is: >>>%s<<< (length = %lu)\n"),answer);
    free(buffer);
    return 0;
}
,

MSDN 明确指出通常最大路径长度为 260 个字符:

在 Windows API 中(除了下面讨论的一些例外 段落),路径的最大长度为 MAX_PATH,即 定义为 260 个字符。

https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd

文章还指出,从某些 Windows 版本开始,应用程序可以通过清单选择加入长路径。

An error happened during template parsing (template:

An error happened during template parsing (template: "class path resource [templates/index.h...

转自 https://blog.csdn.net/qq_41426326/article/details/88837112

在开发 springboot 的时候,进行 modelAndView 视图层映射的时候,一直出现 

An error happened during template parsing (template: "class path resource [templates/index.html]")

模板解析过程中发生错误 (模板:“类路径资源 [templates/index.html]”)

在向 index.html 映射的时候出现错误,小编在和其他程序员一样打开了百度开始搜索,有各种说法

1. 配置文件问题.(我重新看了一遍确定没有问题,但是还是错误)

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/static/
2. 说是 @Controller 和 @RestController 功能不一样,将 @Controller 修改为 @RestController 在加上 @ResponseBody (依然无效)、

3. 说在映射的时候实体类没有 get 方法,为变量加上 get 就可以了(结果我本来就有 get 方法的)

4. 还有说在 pom.xml 文件下的 build 配置 (都不是这个错误的解决方案)

<resources>
<resource>
<directory>sre/main/resources</directory>
</resource>
</resources>
最后小编早上智商最高峰的时候发现了这个小小小问题

 

在这附上小编 index.html 的文件开头,就是因为加了

https: xmlns:https="http://www.w3.org/1999/xhtml"

xmlns:th="http://www.thymeleaf.org"
导致调用的时候原本要调用第二句话的代码调用了第一句代码中的方法发生错误,把第一句代码删除就可以了

小编总结了一下,一般系统出现以下错误

An error happened during template parsing (template: "class path resource [templates/index.html]")

大家可以去看看视图层,并不是 java 代码出现错误.

An error happened during template parsing (template: "class path resource [templates/user.html]

An error happened during template parsing (template: "class path resource [templates/user.html]

问题:

An error happened during template parsing (template: "class path resource [templates/user.html]")

 

 解决方法:

1.配置文件问题。根据问题描述,问题可能为想要去的地址路径错误。解决方法:修改路径。

 

 

 

 2.@RestController

@RestController相当于@Response + @Controller,作用是将return的字符串响应在界面上。

而@Controller作用是将return中的字符串拼接配置文件中的前后缀,形成一个html地址,最后在网页上指向这个地址界面。

 两者作用不同。

 

3.为变量加上get

实体类中可能没有getter and setter方法,加上。

或者可能是LomBok出问题了,重启或者刷新maven包可能可以解决。

 

4.xmlns冲突。可能同时设置了 “https: xmlns:https="http://www.w3.org/1999/xhtml" ”和 “xmlns:th="http://www.thymeleaf.org" ”。删去“https: xmlns:https="http://www.w3.org/1999/xhtml" ”即可。

 

5.(我的问题)进行select搜索时,数据库中没有id=“111”这个数据!所以导致页面跳转指向不明,导致错误TAT

 

高了,血压高了!!!

 

写代码须细心啊TAT

   

attempted relative import with no known parent package

attempted relative import with no known parent package

最稳的方法,加入父路径的绝对路径
import sys
sys.path.append(os.path.abspath(os.path.dirname(file) + ‘/’ + ‘…’))

在这里插入图片描述

比如上面,位于不同文件夹下的两个py文件,当folder2的test2.py要调用folder1的test1.py时,
在 test2.py文件中添加下面的代码即可

import sys,os
sys.path.append(os.path.abspath(os.path.dirname(__file__) + ''/'' + ''..''))

from folder1 import test1

c# – GetCustomAttributes不返回值

c# – GetCustomAttributes不返回值

我已经定义了一个自定义属性
[AttributeUsage(AttributeTargets.Property )]
public class FieldAttribute: Attribute
{
    public FieldAttribute(string field)
    {
        this.field = field;
    }
    private string field;

    public string Field
    {
        get { return field; }

    }
}

我的使用自定义属性的类如下所示

[Serializable()]   
public class DocumentMaster : DomainBase
{

    [Field("DOC_CODE")]
    public string DocumentCode { get; set; }


    [Field("DOC_NAME")]
    public string DocumentName { get; set; }


    [Field("REMARKS")]
    public string Remarks { get; set; }


   }
}

但是当我尝试获取自定义属性的值时,它返回null对象

Type typeOfT = typeof(T);
T obj = Activator.CreateInstance<T>();

PropertyInfo[] propInfo = typeOfT.GetProperties();

foreach (PropertyInfo property in propInfo)
{

     object[] colName = roperty.GetCustomAttributes(typeof(FieldAttributes),false);
     /// colName has no values.
}

我错过了什么?

解决方法

错字:应该是typeof(FieldAttribute).有一个不相关的系统枚举叫做FieldAttributes(在System.Reflection中,你在using指令中有,因为PropertyInfo正确解析).

此外,这更容易使用(假设该属性不允许重复):

var field = (FieldAttribute) Attribute.GetCustomAttribute(
          property,typeof (FieldAttribute),false);
if(field != null) {
    Console.WriteLine(field.Field);
}

我们今天的关于GetTempPathA 我如何提前知道尺寸? 返回值getsizeof返回的分享就到这里,谢谢您的阅读,如果想了解更多关于An error happened during template parsing (template: "class path resource [templates/index.h...、An error happened during template parsing (template: "class path resource [templates/user.html]、attempted relative import with no known parent package、c# – GetCustomAttributes不返回值的相关信息,可以在本站进行搜索。

本文标签: