ERROR_DATATYPE_MISMATCH 0X0000065D: Wrong data type fix
This error hits when a Windows API call or script sends the wrong data type—like a string where a number is expected. The fix is to check and convert the data type at the source.
You're running a script or a legacy app, maybe a PowerShell automation or an old VBA macro in Excel 2016, and bam—error 0x0000065D pops up. The exact text says "Data supplied is of wrong type." I've seen this most often when someone passes a string like "123" to a function that expects an integer, or when a registry API call gets a DWORD value where a string was expected. The trigger is almost always a mismatch between what a function expects and what you give it.
What's actually happening?
Windows has strict type checking in its API calls. Under the hood, functions like RegSetValueEx or WriteProcessMemory expect specific data types—integers, strings, binary blobs. If you feed a string where it expects a 32-bit integer, the system throws 0x0000065D. It's not a bug in Windows. It's a bug in your code or the data you're passing. The real fix is to trace back to the source of that data and either convert it or correct the call.
Fix step-by-step
- Pinpoint the exact line or function call that fails. If you're in PowerShell, run
$Error[0] | fl * -Forceto see the full error record. In VBA, useErr.NumberandErr.Description. Write down the function name. For example,RegSetValueExin a registry script. - Check the data type expected by that function. Open the Microsoft documentation for that function. For registry calls, the
dwTypeparameter tells you—REG_DWORD for 32-bit numbers, REG_SZ for strings. For other APIs, look at the parameter list on MSDN. I always keep a browser tab open to learn.microsoft.com for this. - Examine the data you're passing. In PowerShell, output the variable with
GetType(). For example:$myVar.GetType().FullName. If it showsSystem.Stringbut the function expectsSystem.Int32, that's your mismatch. In VBA, useTypeName(myVar). - Convert the data to the correct type.
- PowerShell: Convert a string to integer with
[int]$myVar. Convert to double with[double]$myVar. For booleans, use[bool]::Parse($myVar). - VBA: Use
CInt()for integer,CLng()for long,CDbl()for double. For registry, useCBool()if REG_DWORD holds a boolean. - C/C++: Use
atoi()for string to int,strtol()for more control.
- PowerShell: Convert a string to integer with
- Test the corrected call. Run the script or macro again. If the error disappears, you're done. If it persists, move to the next step.
- Check for hidden characters or nulls. Sometimes a string looks like "123" but has a trailing newline or null byte. In PowerShell, output
$myVar.Lengthand compare to expected. Strip whitespace with$myVar.Trim(). In VBA, useTrim(myVar). - Review the calling code for type mismatches in structures. For example, if you're passing a
SYSTEMTIMEstructure but filled it with strings instead of integers, you'll get this error. Check every field's type against the structure definition.
If it still fails
Here's what I've seen trip people up after the basics are covered:
- 64-bit vs 32-bit data sizes. On a 64-bit system, some API functions expect a
DWORD(32-bit) but you might be passing aLONG(32-bit signed) and the function wants unsigned. Use[UInt32]in PowerShell orDWORDin C++. - Registry redirection. If you're running a 32-bit script on a 64-bit Windows 10, the registry path might be virtualized under
Wow6432Node. The data type returned there might differ. Always useRegOpenKeyExwithKEY_WOW64_64KEYflag to access the real 64-bit registry. - COM object methods. If the error comes from a COM component like
Scripting.FileSystemObject, the method might expect aVariantor a specific subtype. UseVarType()in VBA to check what the COM object sees. - Log the exact hex value. If you still see 0x0000065D, capture the full error with
Get-Errorin PowerShell 7 orFormat-Listin older versions. Post the full output to a forum—sometimes the error code alone isn't enough.
The bottom line: this error is almost always your code, not Windows. Take a breath, check the data types at the boundary where the API call happens, and convert explicitly. You'll have it fixed in minutes.
Was this solution helpful?