lemme just write a python script to talk to a cross-platform c++ program through shared memory on win32.

this certainly won't be an infinite nightmare, right?

I'm using pywin32 which doesn't give me the ability to distinguish between opening a named shared memory area and creating one, so it succeeds but just because it creates a new shared memory area for me full of nothing

guess I'm gonna have to switch to ctypes!

the C++ code calls CreateFileMappingA( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, memory_map_size, "DWD_GAMELINK_MMAP_R4");

and then on python, I call
OpenFileMappingA(FILE_MAP_ALL_ACCESS, False, "DWD_GAMELINK_MMAP_R4") and get a File Not Found error.

hmmm.

unicode: the DNS of filename problems

yeah I don't think pywin32's mmapfile lets you use an ASCII filename, and windows apparently matches named shared memory by the bytes of the name, not the value of the characters. so a unicode "foo" and an ascii "foo" are different mappings

or maybe it was just that I was calling OpenFileMappingA with a unicode string, which is obviously wrong.

That still doesn't explain why pywin32 wasn't working, and since I've already written the ctypes equivalent, I'm not gonna look into it

cancel the celebrations, I've mapped the named shared memory supposedly properly but when I read from it I get a 0.

it should be a 4. So this isn't working

I'm definitely opening the mapping, though. if I change the name to "foobar" I get a FileNotFound error. HMMM

ugh I'm probably gonna have to write some C++ code to get it working, and then once I know what's wrong, I can translate that to python

I used cheat engine to explore the memory regions of my python script, and it DOES have an appropriately-sized mapped region, but it similarly seems to be full of zeros.

Follow

@foone Did you map it as private / CoW when you wrote to it, thus only wtiting to a copy instead the original?

Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!