DllImportAttribute.BestFitMapping Campo
Definição
Habilita ou desabilita o comportamento de mapeamento mais adequado ao converter caracteres Unicode em caracteres ANSI.Enables or disables best-fit mapping behavior when converting Unicode characters to ANSI characters.
public: bool BestFitMapping;
public bool BestFitMapping;
val mutable BestFitMapping : bool
Public BestFitMapping As Boolean
Valor do campo
Exemplos
Em alguns casos, Visual Basic desenvolvedores usam o DllImportAttribute , em vez da Declare instrução, para definir uma função de dll no código gerenciado.In some cases, Visual Basic developers use the DllImportAttribute, instead of the Declare statement, to define a DLL function in managed code. Definir o BestFitMapping campo é um desses casos.Setting the BestFitMapping field is one of those cases. O exemplo a seguir mostra como aplicar a segurança de mapeamento de caractere mais estrita a uma plataforma que invoca definições de método especificando o conjunto de caracteres ANSI, desabilitando melhor ajuste de comportamento de mapeamento e gerando uma exceção em caracteres Unicode não mapeados.The following example shows how to apply the strictest character mapping security to a platform invoke method definitions by specifying the ANSI character set, disabling best fit mapping behavior, and throwing an exception on unmapped Unicode characters.
[DllImport("My.dll", CharSet = CharSet::Ansi,
BestFitMapping = false,
ThrowOnUnmappableChar = true)]
int SomeFuncion2(int parm);
[DllImport("My.dll", CharSet = CharSet.Ansi,
BestFitMapping = false,
ThrowOnUnmappableChar = true)]
internal static extern int SomeFuncion2(int parm);
<DllImport("My.dll", CharSet:=CharSet.Ansi,
BestFitMapping:=False,
ThrowOnUnmappableChar:=True)>
Friend Shared Function SomeFuncion2(parm As Integer) As Integer
End Function
Comentários
Se o true comportamento de mapeamento de melhor ajuste estiver habilitado; caso contrário, o mapeamento de melhor ajuste será desabilitado.If true, best-fit mapping behavior is enabled; otherwise, best-fit mapping is disabled. O BestFitMapping campo é true por padrão.The BestFitMapping field is true by default. As configurações deste campo substituem as configurações de qualquer nível do System.Runtime.InteropServices.BestFitMappingAttribute atributo.Settings for this field override the any level settings for the System.Runtime.InteropServices.BestFitMappingAttribute attribute.
Cuidado
Determinados caracteres Unicode são convertidos em caracteres perigosos, como o caractere de barra invertida \ , que pode alterar um caminho inadvertidamente.Certain Unicode characters are converted to dangerous characters, such as the backslash '\' character, which can inadvertently change a path. Ao definir o ThrowOnUnmappableChar campo como true , você pode sinalizar a presença de um caractere mapeável para o chamador lançando uma exceção.By setting the ThrowOnUnmappableChar field to true, you can signal the presence of an unmappable character to the caller by throwing an exception.
Cuidado
Você não pode alterar os valores padrão fornecidos pelos BestFitMapping ThrowOnUnmappableChar campos e ao passar uma matriz gerenciada cujos elementos são caracteres ANSI ou LPSTRs para uma matriz segura não gerenciada.You cannot change the default values provided by the BestFitMapping and ThrowOnUnmappableChar fields when passing a managed array whose elements are ANSI Chars or LPSTRs to an unmanaged safe array. O mapeamento de melhor ajuste está sempre habilitado e nenhuma exceção é lançada.Best-fit mapping is always enabled and no exception is thrown. Lembre-se de que essa combinação pode comprometer seu modelo de segurança.Be aware that this combination can compromise your security model.