You are not logged in.

#1 2006-08-27 14:55:06

alikas
Member
From: Lithuania, Vilnius
Registered: 2006-05-24
Posts: 319
Website

How convert Windows C++ code to Linux?

How convert Windows C++ code to Linux code?


Goodbye!

Offline

#2 2006-08-27 15:31:46

ise
Developer
From: Karlsruhe / Germany
Registered: 2005-10-06
Posts: 404
Website

Re: How convert Windows C++ code to Linux?

Hi,

is it plain c++ code or are there any MFC classes included or any other windows libraries?? If not, just compile it under Linux and look for errors to fix.

Another tip: Look at right typo of the includes. For windows lower cases are the same as upper cases.

Write your own makefile to manage the compilation, or use autoconf/automake to handle it.

Have fun....

Daniel

Offline

#3 2006-08-27 16:16:15

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: How convert Windows C++ code to Linux?

[Moved to General Programming Forum.]

Offline

#4 2006-08-27 17:34:36

alikas
Member
From: Lithuania, Vilnius
Registered: 2006-05-24
Posts: 319
Website

Re: How convert Windows C++ code to Linux?

Code include only:
#include <windows>
#include <string>
And 'winmm' libarary.
Thanks, but first error is: - 'error: windows.h:' - not is that file.
With what header need change 'windows.h'?
I do not know about makefiles, how need it edit...


Goodbye!

Offline

#5 2006-08-27 18:09:40

ise
Developer
From: Karlsruhe / Germany
Registered: 2005-10-06
Posts: 404
Website

Re: How convert Windows C++ code to Linux?

'windows.h' is the standard header for windows functions.
That doesn't exists in Linux. I don't know which functions you are calling from there....Delete the  "#include <windows>"-line and look what happen next...

So there is no exact replacement for this header-file. And I don't know which functions windows.h provides. I don't use windows (neither in coding nor in daily use).

'string' exists on both, it's a standard c++ header.

How you manage makefiles and so on, look at the website of automake and autoconf: http://www.gnu.org/software/autoconf/ http://www.gnu.org/software/automake/

Offline

#6 2006-08-28 02:52:06

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: How convert Windows C++ code to Linux?

This is one of those things that can either be really hard or really easy. If the code in question is written in such a way that the Windows-specific bits can be easily replaced, it's a simple matter of tracking down the functions it uses and plugging in Linux functions instead. If it depends more heavily on things that Windows provides, you'll have to rewrite a substantial portion of the code to make it work.

Ise's advice is a good way to get started if you're not already familiar with the code: comment out the spots where Windows-specific headers are included then fix what breaks.

Offline

#7 2006-08-28 04:17:23

alikas
Member
From: Lithuania, Vilnius
Registered: 2006-05-24
Posts: 319
Website

Re: How convert Windows C++ code to Linux?

Thanks,
Maybe someone can convert this simple windows code to linux:

 PlaySoundA("a.wav", NULL, SND_FILENAME | SND_ASYNC);

or this:

char b[999999];
WAVEFORMATEX wfex;HWAVEOUT hwo;
  HMMIO         m_hmmio;       // MM I/O handle for the WAVE
    MMCKINFO      m_ck;          // Multimedia RIFF chunk
    MMCKINFO      m_ckRiff;      // Use in opening a WAVE file
    DWORD         m_dwSize=0;      // The size of the wave file

  WAVEHDR whdr;
HANDLE hDoneEvent = CreateEventA(NULL, FALSE, FALSE, "DONE_EVENT");

wfex.wFormatTag      = WAVE_FORMAT_PCM;
    wfex.nChannels       = 1;
    wfex.nSamplesPerSec  = 22050;
    wfex.nAvgBytesPerSec = 44100;
    wfex.nBlockAlign     = 2;
    wfex.wBitsPerSample  = 16;
    waveOutOpen(&hwo, WAVE_MAPPER, &wfex,(DWORD) hDoneEvent, 0,CALLBACK_EVENT);
m_hmmio = mmioOpen("a.wav", NULL, MMIO_ALLOCBUF | MMIO_READ );
            MMCKINFO    ckIn;    // chunk info. for general use.
            mmioDescend( m_hmmio, &m_ckRiff, NULL, 0 );
            mmioDescend( m_hmmio, &ckIn, &m_ckRiff,MMIO_FINDCHUNK );
            mmioSeek( m_hmmio, m_ckRiff.dwDataOffset + sizeof(FOURCC),SEEK_SET );
            m_ck.ckid = mmioFOURCC('d', 'a', 't', 'a');
            mmioDescend( m_hmmio, &m_ck, &m_ckRiff,MMIO_FINDCHUNK );// )
            m_dwSize =m_ck.cksize;
            MMIOINFO mmioinfoIn; // current status of m_hmmio
            mmioGetInfo( m_hmmio, &mmioinfoIn, 0 );
            for(DWORD cT=0;cT<m_dwSize;cT++) {
                if(mmioinfoIn.pchNext==mmioinfoIn.pchEndRead) {
                    mmioAdvance( m_hmmio, &mmioinfoIn, MMIO_READ );
                }
                *((BYTE*)b+cT)=*((BYTE*)mmioinfoIn.pchNext);
                mmioinfoIn.pchNext++;
            }
            mmioClose(m_hmmio,0);
    ZeroMemory(&whdr, sizeof(WAVEHDR));
                whdr.lpData=b;
                whdr.dwBufferLength =m_dwSize;
                waveOutPrepareHeader(hwo, &whdr, sizeof(WAVEHDR));
                waveOutWrite(hwo, &whdr, sizeof(WAVEHDR));
                while (!(whdr.dwFlags & WHDR_DONE)) {
                    WaitForSingleObject(hDoneEvent, INFINITE);
                }
                waveOutUnprepareHeader(hwo, &whdr, sizeof(WAVEHDR));
waveOutClose(hwo);

But I use Quincy (http://codecutter.net/tools/quincy/)with Wine  and creating that .exe files.
Quincy not create  'makefile' (I not understand why me need 'makefile' edit and from were I can get it?) files, it create 'filename.o' files only.
And I understoond, then read Wine text, that with Wine (http://www.winehq.com/) possible convert Windows code to Linux, but do not known how.
How convert Windows code to Linux with Wine?


Goodbye!

Offline

#8 2006-08-28 12:45:16

alikas
Member
From: Lithuania, Vilnius
Registered: 2006-05-24
Posts: 319
Website

Re: How convert Windows C++ code to Linux?

Not use "#include <windows>" and look what happen next with file that use only this lines:

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)
{
PlaySoundA("a.wav", NULL, SND_FILENAME | SND_ASYNC); 
return 0;
}

:[al@myhost kalba]$ g++ ./playsound.cpp
./playsound.cpp:1: error: expected initializer before 'WinMain'


Goodbye!

Offline

#9 2006-08-28 17:52:27

sweiss
Member
Registered: 2004-02-16
Posts: 635

Re: How convert Windows C++ code to Linux?

Well, no wonder. All of these macros are Windows specific. It seems that this code is simply not portable, so your best chance would be using winelib.
I've never used winelib myself, but I'm sure google would prove useful.

Offline

#10 2006-08-28 20:00:01

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: How convert Windows C++ code to Linux?

Check out the source for aplay to see how to do sound playback in a linux environment.

Offline

#11 2006-08-29 03:41:41

alikas
Member
From: Lithuania, Vilnius
Registered: 2006-05-24
Posts: 319
Website

Re: How convert Windows C++ code to Linux?

Thanks, but were I can check out the source for aplay to see how to do sound playback in a linux environment?


Goodbye!

Offline

#12 2006-08-29 04:18:56

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: How convert Windows C++ code to Linux?

aplay belongs to the alsa-utils package. The sources are:
ftp://ftp.alsa-project.org/pub/utils/al … 11.tar.bz2

Offline

#13 2006-08-29 11:37:30

brain0
Developer
From: Aachen - Germany
Registered: 2005-01-03
Posts: 1,382

Re: How convert Windows C++ code to Linux?

You should be able to compile Windows API code with libwine. Install wine, add the right include path and try it.

Offline

#14 2006-08-29 14:38:10

alikas
Member
From: Lithuania, Vilnius
Registered: 2006-05-24
Posts: 319
Website

Re: How convert Windows C++ code to Linux?

I have instaled wine with 'pacman -S wine'.
How add right include patch? I not understood.
Thanks!
I check 'aplay.c' in yuo package and it very big file and I can not it compile, maybe somebody can write short complitely code how play WAVE file with Linux.


Goodbye!

Offline

Board footer

Powered by FluxBB