We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,983 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

__uuidof

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

2
Contributors
3
Replies
20 Hours
Discussion Span
2 Years Ago
Last Updated
4
Views
chrishtones
Newbie Poster
16 posts since Jun 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

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

gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0

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?

chrishtones
Newbie Poster
16 posts since Jun 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

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

gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0648 seconds using 2.68MB