need some C/C++ help (solved)

You can talk about almost anything that you want to on this board.

Moderator: Moderators

Post Reply
User avatar
Memblers
Site Admin
Posts: 3777
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

need some C/C++ help (solved)

Post by Memblers » Sat Feb 23, 2019 9:06 am

I'm having a dumb problem, probably with a dumb cause, but I haven't been able to figure it out.

I'm working on UART emulation code in C, so I can emulate the USB adapter from the Cheapocabra devkit. I was planning to post it once I get it tested and cleaned up, but for now I'm kinda stuck, so hopefully someone can help spot the problem. The code in async.c is isn't really in a usable state, it's kinda hard to get it working when I can't properly test it though..

Normally I only work with C, so maybe it's C++ related? What I've got is some code that works every time when I compile and run it by itself with a very simple main() function. Now I'm trying to add it into Nintendulator for testing, and it fails every time. serial_open() in serial_windows.c is where it fails. Works every time in a stand-alone test (C compiler), fails every time built with Nintendulator (C++). Checking GetLastError() returns code 2, which is "file not found". Stepping through it with a debugger hasn't been very enlightening, just windows kernal stuff viewed as a disassembly.. yeah.. not sure where to go from there.

Is there some reason why this would fail when being used in Nintendulator, but works fine in my own little "main.c" file?
-header files are wrapped in extern C{}
-using visual studio 2017
-I'm calling async_open() from Nintendulator.cpp, just before it enters the main loop
-serial.h, serial_windows.c, serial_linux.c is not my code, they're some simple libraries I've been using and modifying
Attachments
async.zip
(9.16 KiB) Downloaded 218 times

User avatar
Dwedit
Posts: 4246
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: need some C/C++ help

Post by Dwedit » Sat Feb 23, 2019 10:25 am

Seems that it calls CreateFile on "\\.\COM1" or something like that. A good place to stick breakpoints is right around CreateFile to see if the filename is okay.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
samophlange
Posts: 46
Joined: Sun Apr 08, 2018 11:45 pm
Location: Southern California

Re: need some C/C++ help

Post by samophlange » Sat Feb 23, 2019 1:29 pm

The first thing to do would be to ensure that you're passing the exact same parameters to CreateFile in both situations. If that is the case, maybe Nintendulator is also accessing that resource in an exclusive way? Or it may be doing other things (including loading in DLLs) which changes the context in which that function operates. I would be surprised if this were due to Nintendulator being a C++ application.

User avatar
Memblers
Site Admin
Posts: 3777
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: need some C/C++ help

Post by Memblers » Sun Feb 24, 2019 5:26 am

Thanks for the tips, I still couldn't figure it out in Nintendulator. It must be somehow using the wrong character format for the filename, doesn't seem like there could be anything else.

I've resolved the problem for now by moving over to FCEUX. Builds fine and opens the COM port, I'm not stuck anymore. UART emulation coming soon.

User avatar
Dwedit
Posts: 4246
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: need some C/C++ help (solved)

Post by Dwedit » Sun Feb 24, 2019 10:01 am

Oh wait, yeah, forgot that "CreateFile" was a macro and not a function.
CreateFileA and CreateFileW are the real functions, and defining UNICODE can break that.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Post Reply