How to assign a string to a Win32 LPCWSTR?

How can I correctly assign a value to a Win32 LPCWSTR value?

import win "core:sys/windows"

create_window :: proc() -> Window {
using win

...

class_name := L("My Window")

wc := WNDCLASSEXW {
    lpszClassName = class_name,
}

...

Generates the following error:

D:/Repos/demo/code/window.odin(22:19) Error: Cannot assign value 'class_name' of type '[^]u16' to 'cstring16' in a structure literal 
        lpszClassName = class_name,
                        ^~~~~~~~~^ 

I used an example from Karl’s Odin Book and also his GitHub repo, which shows this syntax. The WNDCLASSW and WNDCLASSEXW are slightly different structs, but the type of lpszClassName is the same.

I don’t know if something has changed between Odin versions that would impact this. I’m on:

odin version
odin version dev-2025-11-nightly:e5153a9

(It says nightly, but it’s from the main release page on GitHub.

The AI suggested a fixed array of characters, but that doesn’t sound like a great solution.

How should I be doing this?

have to do a cast from the multi pointer to a cstring16

lpszClassName = cstring16(class_name)
1 Like

You can also just give it the string literal directly, or specifically type class_name, e.g. class_name: cstring16 = "My Window". A string literal can implicitly convert to a cstring16, so windows.L isn’t really needed now.