Since __uuidof is a C++ only operator, how would I retrieve the GUID of an object in C?

Recommended Answers

All 3 Replies

Do you mean, how does a C object file that has been linked into a C++ project, retrieve/accept the GUID of an object?

Do you mean, how does a C object file that has been linked into a C++ project, retrieve/accept the GUID of an object?

Say I'm writing a program in C and need to use a function like this:
void SomeFunction(IID* refiid);

In C++ I would do this:
SomeFunction(__uuidof(&SomeObject));

How would I call that function in C?

I know how to solve this in Linux using GCC but the solution is not portable...That said you should be able to use the concept which is....wrapping the C++ functionality in a C calling sequence, see below

testit.cpp

#include <iostream>

extern "C" void PrintStr(char *str);

void PrintStr(char *str)
{
	std::cout << "From Cpp Object file->" << str << std::endl;
}

testit.h

void PrintStr(char *str);

test.c

#include "testit.h"

int main()
{
	char ch[] = "From the C program";

	PrintStr(ch);
	return 0;
}

And my compile lines

g++ -Wall -ansi -pedantic -c testit.cpp
gcc testit.o test.c -o test -Wall -ansi -pedantic -lstdc++

Note the inclusion of the standard C++ library with the -lstdc++ switch..Hope this helps.

Output:

From Cpp Object file->From the C program

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.