Conversation

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?

2
0
0

@foone that doesn't sound so bad to me

0
0
0

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

2
0
0

guess I'm gonna have to switch to ctypes!

1
0
0
@foone PythonForWindows worked pretty well for me for ALPC based stuff: https://github.com/hakril/PythonForWindows
0
0
0

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.

1
0
0

unicode: the DNS of filename problems

1
0
1

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

3
0
0

@whitequark yeah I think you might be right. I think I was converting it incorrectly somehow

0
0
0

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

1
0
0

@foone do you mean wide chars (16 bit)?

1
0
0

@kw217 yeah. I meant UNICODE in the windows sense of UCS-2

0
0
0

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

1
0
0

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

1
0
0

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

1
0
0

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.

2
0
0

and then I spied on DOSBox-X, which is supposed to be the program filling out that shared mapping, and... it's empty there too!

1
0
0

@foone i am loathe to ask this, but is there not a generic mmap implementation for python that unfucks whatever infelicities befall the win32 API?

1
0
0

@nabijaczleweli there is, but it doesn't support the kind of named shared region I need

0
0
0

static void shared_memory_init()
{
if (sdl.gamelink.snoop) return;

if you're in snoop mode, it doesn't initialize the segment.

WHY THE FUCK NOT

1
0
0

yep. I turned off snoop mode and now it works. I see a 4 where I expect it

1
0
0

well I think this debugging session used up all my energy I was going to write some software that used this shit, but hey. at least step 1 works now

0
0
0